List of usage examples for android.widget LinearLayout setVisibility
@RemotableViewMethod public void setVisibility(@Visibility int visibility)
From source file:com.asksven.betterbatterystats.adapters.StatsAdapter.java
public View getView(int position, View convertView, ViewGroup viewGroup) { StatElement entry = m_listData.get(position); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.m_context); boolean bShowBars = sharedPrefs.getBoolean("show_gauge", false); if (LogSettings.DEBUG) { Log.i(TAG, "Values: " + entry.getVals()); }//from w w w .j a v a 2 s.c o m if (convertView == null) { LayoutInflater inflater = (LayoutInflater) m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // depending on settings show new pie gauge or old bar gauge if (!bShowBars) { convertView = inflater.inflate(R.layout.stat_row, null); } else { convertView = inflater.inflate(R.layout.stat_row_gauge, null); } } final float scale = this.m_context.getResources().getDisplayMetrics().density; TextView tvName = (TextView) convertView.findViewById(R.id.TextViewName); ///////////////////////////////////////// // we do some stuff here to handle settings about font size and thumbnail size String fontSize = sharedPrefs.getString("medium_font_size", "16"); int mediumFontSize = Integer.parseInt(fontSize); //we need to change "since" fontsize tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, mediumFontSize); // We need to handle an exception here: Sensors do not have a name so we use the fqn instead if (entry instanceof SensorUsage) { tvName.setText(entry.getFqn(UidNameResolver.getInstance(m_context))); } else { tvName.setText(entry.getName()); } boolean bShowKb = sharedPrefs.getBoolean("enable_kb", true); ImageView iconKb = (ImageView) convertView.findViewById(R.id.imageKB); iconKb.setVisibility(View.INVISIBLE); TextView tvFqn = (TextView) convertView.findViewById(R.id.TextViewFqn); tvFqn.setText(entry.getFqn(UidNameResolver.getInstance(m_context))); TextView tvData = (TextView) convertView.findViewById(R.id.TextViewData); // for alarms the values is wakeups per hour so we need to take the time as reference for the text if (entry instanceof Alarm) { tvData.setText(entry.getData((long) m_timeSince)); } else { tvData.setText(entry.getData((long) m_maxValue)); } //LinearLayout myLayout = (LinearLayout) convertView.findViewById(R.id.LinearLayoutBar); LinearLayout myFqnLayout = (LinearLayout) convertView.findViewById(R.id.LinearLayoutFqn); LinearLayout myRow = (LinearLayout) convertView.findViewById(R.id.LinearLayoutEntry); // long press for "copy to clipboard" convertView.setOnLongClickListener(new OnItemLongClickListener(position)); if (!bShowBars) { GraphablePie gauge = (GraphablePie) convertView.findViewById(R.id.Gauge); ///////////////////////////////////////// // we do some stuff here to handle settings about font size and thumbnail size String iconDim = sharedPrefs.getString("thumbnail_size", "56"); int iconSize = Integer.parseInt(iconDim); int pixels = (int) (iconSize * scale + 0.5f); //we need to change "since" fontsize gauge.getLayoutParams().height = pixels; gauge.getLayoutParams().width = pixels; gauge.requestLayout(); //////////////////////////////////////////////////////////////////////////////////// if (entry instanceof NetworkUsage) { gauge.setValue(entry.getValues()[0], ((NetworkUsage) entry).getTotal()); } else { double max = m_maxValue; // avoid rounding errors leading to values > 100 % if (entry.getValues()[0] > max) { max = entry.getValues()[0]; Log.i(TAG, "Upping gauge max to " + max); } gauge.setValue(entry.getValues()[0], max); } } else { GraphableBars buttonBar = (GraphableBars) convertView.findViewById(R.id.ButtonBar); int iHeight = 10; try { iHeight = Integer.valueOf(sharedPrefs.getString("graph_bar_height", "10")); } catch (Exception e) { iHeight = 10; } if (iHeight == 0) { iHeight = 10; } buttonBar.setMinimumHeight(iHeight); buttonBar.setName(entry.getName()); buttonBar.setValues(entry.getValues(), m_maxValue); } ImageView iconView = (ImageView) convertView.findViewById(R.id.icon); LinearLayout iconLayout = (LinearLayout) convertView.findViewById(R.id.LayoutIcon); ///////////////////////////////////////// // we do some stuff here to handle settings about font size and thumbnail size String iconDim = sharedPrefs.getString("thumbnail_size", "56"); int iconSize = Integer.parseInt(iconDim); int pixels = (int) (iconSize * scale + 0.5f); //we need to change "since" fontsize iconView.getLayoutParams().width = pixels; iconView.getLayoutParams().height = pixels; iconView.requestLayout(); //n 20;setLay.setTextSize(TypedValue.COMPLEX_UNIT_DIP, iconSize); //////////////////////////////////////////////////////////////////////////////////// // add on click listener for the icon only if KB is enabled // if (bShowKb) // { // // set a click listener for the list // iconKb.setOnClickListener(new OnIconClickListener(position)); // } // show / hide fqn text if ((entry instanceof Process) || (entry instanceof State) || (entry instanceof Misc) || (entry instanceof NativeKernelWakelock) || (entry instanceof Alarm) || (entry instanceof SensorUsage)) { myFqnLayout.setVisibility(View.GONE); } else { myFqnLayout.setVisibility(View.VISIBLE); } // show / hide package icons (we show / hide the whole layout as it contains a margin that must be hidded as well if ((entry instanceof NativeKernelWakelock) || (entry instanceof State) || (entry instanceof Misc)) { iconView.setVisibility(View.GONE); } else { iconView.setVisibility(View.VISIBLE); iconView.setImageDrawable(entry.getIcon(UidNameResolver.getInstance(m_context))); // set a click listener for the list iconView.setOnClickListener(new OnPackageClickListener(position)); } // add on click listener for the list entry if details are availble if ((entry instanceof Alarm) || (entry instanceof NativeKernelWakelock) || (entry instanceof SensorUsage)) { convertView.setOnClickListener(new OnItemClickListener(position)); } // // show / hide set dividers // ListView myList = (ListView) convertView.getListView(); //findViewById(R.id.id.list); // myList.setDivider(new ColorDrawable(0x99F10529)); // myList.setDividerHeight(1); return convertView; }
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
private void listDirFilterLocal(SyncTaskItem sti, String prof_master, final ArrayList<String> dir_filter, final AdapterFilterList fla, final NotifyEvent p_ntfy) { final String cdir = sti.getMasterDirectoryName(); String localBaseDir_t = mGp.internalRootDirectory; if (sti.getMasterFolderType().equals(SyncTaskItem.SYNC_FOLDER_TYPE_SDCARD)) localBaseDir_t = mGp.sdcardRootDirectory; final String localBaseDir = localBaseDir_t; //??/*from w w w.j av a 2 s .com*/ final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.item_select_list_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_title_view); final TextView title = (TextView) dialog.findViewById(R.id.item_select_list_dlg_title); final TextView subtitle = (TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); subtitle.setTextColor(mGp.themeColorList.text_color_dialog_title); title.setText(mContext.getString(R.string.msgs_filter_list_dlg_add_dir_filter)); subtitle.setText(mContext.getString(R.string.msgs_current_dir) + " " + localBaseDir + "/" + cdir); final TextView dlg_msg = (TextView) dialog.findViewById(R.id.item_select_list_dlg_msg); final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn); final LinearLayout ll_context = (LinearLayout) dialog.findViewById(R.id.context_view_file_select); ll_context.setVisibility(LinearLayout.VISIBLE); final ImageButton ib_select_all = (ImageButton) ll_context.findViewById(R.id.context_button_select_all); final ImageButton ib_unselect_all = (ImageButton) ll_context.findViewById(R.id.context_button_unselect_all); dlg_msg.setVisibility(TextView.VISIBLE); // if (rows.size()<=2) // ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer)) // .setVisibility(TextView.VISIBLE); CommonDialog.setDlgBoxSizeLimit(dialog, true); final ListView lv = (ListView) dialog.findViewById(android.R.id.list); final TreeFilelistAdapter tfa = new TreeFilelistAdapter(mContext, false, false); lv.setAdapter(tfa); ArrayList<TreeFilelistItem> tfl = createLocalFilelist(true, localBaseDir, "/" + cdir); if (tfl.size() < 1) tfl.add(new TreeFilelistItem(mContext.getString(R.string.msgs_dir_empty))); tfa.setDataList(tfl); lv.setScrollingCacheEnabled(false); lv.setScrollbarFadingEnabled(false); ib_select_all.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < tfa.getDataItemCount(); i++) { TreeFilelistItem tfli = tfa.getDataItem(i); if (!tfli.isHideListItem()) tfa.setDataItemIsSelected(i); } tfa.notifyDataSetChanged(); btn_ok.setEnabled(true); } }); ib_unselect_all.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < tfa.getDataItemCount(); i++) { tfa.setDataItemIsUnselected(i); } tfa.notifyDataSetChanged(); btn_ok.setEnabled(false); } }); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> items, View view, int idx, long id) { final int pos = tfa.getItem(idx); final TreeFilelistItem tfi = tfa.getDataItem(pos); if (tfi.getName().startsWith("---")) return; expandHideLocalDirTree(true, localBaseDir, pos, tfi, tfa); } }); lv.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) { final int t_pos = tfa.getItem(position); final TreeFilelistItem tfi = tfa.getDataItem(t_pos); if (tfi.getName().startsWith("---")) return true; if (!tfa.getDataItem(t_pos).isChecked()) { tfa.setDataItemIsSelected(t_pos); } return true; } }); //OK? btn_ok.setEnabled(false); NotifyEvent ntfy = new NotifyEvent(mContext); //Listen setRemoteShare response ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context arg0, Object[] arg1) { btn_ok.setEnabled(true); } @Override public void negativeResponse(Context arg0, Object[] arg1) { boolean checked = false; for (int i = 0; i < tfa.getDataItemCount(); i++) { if (tfa.getDataItem(i).isChecked()) { checked = true; break; } } if (checked) btn_ok.setEnabled(true); else btn_ok.setEnabled(false); } }); tfa.setCbCheckListener(ntfy); btn_ok.setText(mContext.getString(R.string.msgs_filter_list_dlg_add)); btn_ok.setVisibility(Button.VISIBLE); btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (!addDirFilter(true, tfa, fla, "/" + cdir + "/", dlg_msg)) return; addDirFilter(false, tfa, fla, "/" + cdir + "/", dlg_msg); dialog.dismiss(); p_ntfy.notifyToListener(true, null); } }); //CANCEL? final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn); btn_cancel.setText(mContext.getString(R.string.msgs_filter_list_dlg_close)); btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); p_ntfy.notifyToListener(true, null); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); return; }
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
private void listDirFilterSMB(SyncTaskItem sti, String prof_master, final ArrayList<String> dir_filter, final AdapterFilterList fla, final NotifyEvent p_ntfy) { setSmbUserPass(sti.getMasterRemoteUserID(), sti.getMasterRemotePassword()); String t_remurl = ""; if (sti.getMasterRemoteHostname().equals("")) t_remurl = sti.getMasterRemoteAddr(); else//from w ww. ja v a2 s . co m t_remurl = sti.getMasterRemoteHostname(); String h_port = ""; if (!sti.getMasterRemotePassword().equals("")) h_port = ":" + sti.getMasterRemotePort(); final String remurl = "smb://" + t_remurl + h_port + "/" + sti.getMasterRemoteSmbShareName(); final String remdir = "/" + sti.getMasterDirectoryName() + "/"; NotifyEvent ntfy = new NotifyEvent(mContext); // set thread response ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { final ArrayList<TreeFilelistItem> rows = new ArrayList<TreeFilelistItem>(); @SuppressWarnings("unchecked") ArrayList<TreeFilelistItem> rfl = (ArrayList<TreeFilelistItem>) o[0]; for (int i = 0; i < rfl.size(); i++) { if (rfl.get(i).isDir() && rfl.get(i).canRead()) rows.add(rfl.get(i)); } Collections.sort(rows); if (rows.size() < 1) rows.add(new TreeFilelistItem(mContext.getString(R.string.msgs_dir_empty))); //?? final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.item_select_list_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.item_select_list_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog .findViewById(R.id.item_select_list_dlg_title_view); final TextView title = (TextView) dialog.findViewById(R.id.item_select_list_dlg_title); final TextView subtitle = (TextView) dialog.findViewById(R.id.item_select_list_dlg_subtitle); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); subtitle.setTextColor(mGp.themeColorList.text_color_dialog_title); title.setText(mContext.getString(R.string.msgs_filter_list_dlg_add_dir_filter)); subtitle.setText(mContext.getString(R.string.msgs_current_dir) + " " + remurl + remdir); final TextView dlg_msg = (TextView) dialog.findViewById(R.id.item_select_list_dlg_msg); final LinearLayout ll_context = (LinearLayout) dialog.findViewById(R.id.context_view_file_select); ll_context.setVisibility(LinearLayout.VISIBLE); final ImageButton ib_select_all = (ImageButton) ll_context .findViewById(R.id.context_button_select_all); final ImageButton ib_unselect_all = (ImageButton) ll_context .findViewById(R.id.context_button_unselect_all); final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn); dlg_msg.setVisibility(TextView.VISIBLE); // if (rows.size()<=2) // ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer)) // .setVisibility(TextView.VISIBLE); CommonDialog.setDlgBoxSizeLimit(dialog, true); final ListView lv = (ListView) dialog.findViewById(android.R.id.list); final TreeFilelistAdapter tfa = new TreeFilelistAdapter(mContext, false, false); tfa.setDataList(rows); lv.setAdapter(tfa); lv.setScrollingCacheEnabled(false); lv.setScrollbarFadingEnabled(false); // lv.setFastScrollEnabled(true); ib_select_all.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < tfa.getDataItemCount(); i++) { TreeFilelistItem tfli = tfa.getDataItem(i); if (!tfli.isHideListItem()) tfa.setDataItemIsSelected(i); } tfa.notifyDataSetChanged(); btn_ok.setEnabled(true); } }); ib_unselect_all.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < tfa.getDataItemCount(); i++) { tfa.setDataItemIsUnselected(i); } tfa.notifyDataSetChanged(); btn_ok.setEnabled(false); } }); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> items, View view, int idx, long id) { // ???????? final int pos = tfa.getItem(idx); final TreeFilelistItem tfi = tfa.getDataItem(pos); if (tfi.getName().startsWith("---")) return; expandHideRemoteDirTree(remurl, pos, tfi, tfa); } }); lv.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) { final int t_pos = tfa.getItem(position); final TreeFilelistItem tfi = tfa.getDataItem(t_pos); if (tfi.getName().startsWith("---")) return true; if (!tfa.getDataItem(t_pos).isChecked()) { tfa.setDataItemIsSelected(t_pos); } return true; } }); //OK? btn_ok.setEnabled(false); NotifyEvent ntfy = new NotifyEvent(mContext); //Listen setRemoteShare response ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context arg0, Object[] arg1) { btn_ok.setEnabled(true); } @Override public void negativeResponse(Context arg0, Object[] arg1) { if (tfa.isDataItemIsSelected()) btn_ok.setEnabled(true); else btn_ok.setEnabled(false); } }); tfa.setCbCheckListener(ntfy); btn_ok.setText(mContext.getString(R.string.msgs_filter_list_dlg_add)); btn_ok.setVisibility(Button.VISIBLE); btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (!addDirFilter(true, tfa, fla, remdir, dlg_msg)) return; addDirFilter(false, tfa, fla, remdir, dlg_msg); dialog.dismiss(); p_ntfy.notifyToListener(true, null); } }); //CANCEL? final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn); btn_cancel.setText(mContext.getString(R.string.msgs_filter_list_dlg_close)); btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); p_ntfy.notifyToListener(true, null); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); // dialog.setOnKeyListener(new DialogOnKeyListener(context)); // dialog.setCancelable(false); dialog.show(); } @Override public void negativeResponse(Context c, Object[] o) { p_ntfy.notifyToListener(false, o); } }); createRemoteFileList(remurl, remdir, ntfy, true); }
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
private void selectImportProfileItem(final AdapterSyncTask tfl, final NotifyEvent p_ntfy) { final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.export_import_profile_dlg); dialog.setCanceledOnTouchOutside(false); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.export_import_profile_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); ArrayList<ExportImportProfileListItem> eipl = new ArrayList<ExportImportProfileListItem>(); for (int i = 0; i < tfl.getCount(); i++) { SyncTaskItem pl = tfl.getItem(i); ExportImportProfileListItem eipli = new ExportImportProfileListItem(); eipli.isChecked = true;// w w w. j a va 2 s . co m eipli.item_name = pl.getSyncTaskName(); eipl.add(eipli); } // Collections.sort(eipl, new Comparator<ExportImportProfileListItem>(){ // @Override // public int compare(ExportImportProfileListItem arg0, // ExportImportProfileListItem arg1) { // if (arg0.item_name.equals(arg1.item_name)) return arg0.item_type.compareToIgnoreCase(arg1.item_type); // return arg0.item_name.compareToIgnoreCase(arg1.item_name); // } // }); // ExportImportProfileListItem eipli=new ExportImportProfileListItem(); // eipli.isChecked=true; // eipli.item_type="*"; // eipli.item_name=mContext.getString(R.string.msgs_export_import_profile_setting_parms); // eipl.add(eipli); final AdapterExportImportSyncTask imp_list_adapt = new AdapterExportImportSyncTask(mContext, R.layout.export_import_profile_list_item, eipl); ListView lv = (ListView) dialog.findViewById(R.id.export_import_profile_listview); lv.setAdapter(imp_list_adapt); CommonDialog.setDlgBoxSizeLimit(dialog, true); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.export_import_profile_title_view); final TextView title = (TextView) dialog.findViewById(R.id.export_import_profile_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); title.setText(mContext.getString(R.string.msgs_export_import_profile_title)); // TextView tv_msgx=(TextView)dialog.findViewById(R.id.export_import_profile_msg); // tv_msgx.setVisibility(LinearLayout.GONE); LinearLayout ll_filelist = (LinearLayout) dialog.findViewById(R.id.export_import_profile_file_list); ll_filelist.setVisibility(LinearLayout.GONE); final Button ok_btn = (Button) dialog.findViewById(R.id.export_import_profile_dlg_btn_ok); Button cancel_btn = (Button) dialog.findViewById(R.id.export_import_profile_dlg_btn_cancel); final Button rb_select_all = (Button) dialog.findViewById(R.id.export_import_profile_list_select_all); final Button rb_unselect_all = (Button) dialog.findViewById(R.id.export_import_profile_list_unselect_all); final CheckedTextView ctv_reset_profile = (CheckedTextView) dialog .findViewById(R.id.export_import_profile_list_ctv_reset_profile); final CheckedTextView ctv_import_settings = (CheckedTextView) dialog .findViewById(R.id.export_import_profile_list_ctv_import_settings); final CheckedTextView ctv_import_schedule = (CheckedTextView) dialog .findViewById(R.id.export_import_profile_list_ctv_import_schedule); ctv_reset_profile.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((CheckedTextView) v).toggle(); setImportOkBtnEnabled(ctv_reset_profile, ctv_import_settings, ctv_import_schedule, imp_list_adapt, ok_btn); } }); ctv_import_settings.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((CheckedTextView) v).toggle(); setImportOkBtnEnabled(ctv_reset_profile, ctv_import_settings, ctv_import_schedule, imp_list_adapt, ok_btn); } }); ctv_import_schedule.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((CheckedTextView) v).toggle(); setImportOkBtnEnabled(ctv_reset_profile, ctv_import_settings, ctv_import_schedule, imp_list_adapt, ok_btn); } }); ctv_import_settings.setChecked(true); ctv_import_schedule.setChecked(true); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) { // imp_list_adapt.getItem(pos).isChecked=!imp_list_adapt.getItem(pos).isChecked; // imp_list_adapt.notifyDataSetChanged(); // if (imp_list_adapt.isItemSelected()) { // ok_btn.setEnabled(true); // } else { // ok_btn.setEnabled(false); // } setImportOkBtnEnabled(ctv_reset_profile, ctv_import_settings, ctv_import_schedule, imp_list_adapt, ok_btn); } }); // lv.setOnItemLongClickListener(new OnItemLongClickListener(){ // @Override // public boolean onItemLongClick(AdapterView<?> arg0, View arg1, // int pos, long arg3) { // ccMenu.addMenuItem( // mContext.getString(R.string.msgs_export_import_profile_select_all),R.drawable.blank) // .setOnClickListener(new CustomContextMenuOnClickListener() { // @Override // final public void onClick(CharSequence menuTitle) { // for (int i=0;i<imp_list_adapt.getCount();i++) // imp_list_adapt.getItem(i).isChecked=true; // imp_list_adapt.notifyDataSetChanged(); // ok_btn.setEnabled(true); // } // }); // ccMenu.addMenuItem( // mContext.getString(R.string.msgs_export_import_profile_unselect_all),R.drawable.blank) // .setOnClickListener(new CustomContextMenuOnClickListener() { // @Override // final public void onClick(CharSequence menuTitle) { // for (int i=0;i<imp_list_adapt.getCount();i++) // imp_list_adapt.getItem(i).isChecked=false; // imp_list_adapt.notifyDataSetChanged(); // ok_btn.setEnabled(false); // } // }); // ccMenu.createMenu(); // return false; // } // }); rb_select_all.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < imp_list_adapt.getCount(); i++) imp_list_adapt.getItem(i).isChecked = true; ctv_import_settings.setChecked(true); ctv_import_schedule.setChecked(true); imp_list_adapt.notifyDataSetChanged(); ok_btn.setEnabled(true); } }); rb_unselect_all.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { for (int i = 0; i < imp_list_adapt.getCount(); i++) imp_list_adapt.getItem(i).isChecked = false; ctv_import_settings.setChecked(false); ctv_import_schedule.setChecked(false); imp_list_adapt.notifyDataSetChanged(); ok_btn.setEnabled(false); } }); NotifyEvent ntfy_ctv_listener = new NotifyEvent(mContext); ntfy_ctv_listener.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { // if (imp_list_adapt.isItemSelected()) { // ok_btn.setEnabled(true); // } else { // if (ctv_import_settings.isChecked()) ok_btn.setEnabled(true); // else ok_btn.setEnabled(false); // } setImportOkBtnEnabled(ctv_reset_profile, ctv_import_settings, ctv_import_schedule, imp_list_adapt, ok_btn); } @Override public void negativeResponse(Context c, Object[] o) { } }); imp_list_adapt.setCheckButtonListener(ntfy_ctv_listener); ok_btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (ctv_reset_profile.isChecked()) mGp.syncTaskAdapter.clear(); importSelectedSyncTaskItem(imp_list_adapt, tfl, ctv_import_settings.isChecked(), ctv_import_schedule.isChecked(), p_ntfy); dialog.dismiss(); } }); cancel_btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { dialog.dismiss(); } }); dialog.show(); }
From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java
public DrawerForm(Context context, Context unstyledContext, Callback callback, WatcherService.Client watcherServiceClient) { this.context = context; this.unstyledContext = unstyledContext; this.callback = callback; this.watcherServiceClient = watcherServiceClient; float density = ResourceUtils.obtainDensity(context); LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.setLayoutParams(new SortableListView.LayoutParams(SortableListView.LayoutParams.MATCH_PARENT, SortableListView.LayoutParams.WRAP_CONTENT)); LinearLayout editTextContainer = new LinearLayout(context); editTextContainer.setGravity(Gravity.CENTER_VERTICAL); linearLayout.addView(editTextContainer); searchEdit = new SafePasteEditText(context); searchEdit.setOnKeyListener((v, keyCode, event) -> { if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) { v.clearFocus();/*from w w w .ja va 2s . com*/ } return false; }); searchEdit.setHint(context.getString(R.string.text_code_number_address)); searchEdit.setOnEditorActionListener(this); searchEdit.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI); searchEdit.setImeOptions(EditorInfo.IME_ACTION_GO | EditorInfo.IME_FLAG_NO_EXTRACT_UI); ImageView searchIcon = new ImageView(context, null, android.R.attr.buttonBarButtonStyle); searchIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonForward, 0)); searchIcon.setScaleType(ImageView.ScaleType.CENTER); searchIcon.setOnClickListener(this); editTextContainer.addView(searchEdit, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); editTextContainer.addView(searchIcon, (int) (40f * density), (int) (40f * density)); if (C.API_LOLLIPOP) { editTextContainer.setPadding((int) (12f * density), (int) (8f * density), (int) (8f * density), 0); } else { editTextContainer.setPadding(0, (int) (2f * density), (int) (4f * density), (int) (2f * density)); } LinearLayout selectorContainer = new LinearLayout(context); selectorContainer.setBackgroundResource( ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0)); selectorContainer.setOrientation(LinearLayout.HORIZONTAL); selectorContainer.setGravity(Gravity.CENTER_VERTICAL); selectorContainer.setOnClickListener(v -> { hideKeyboard(); setChanSelectMode(!chanSelectMode); }); linearLayout.addView(selectorContainer); selectorContainer.setMinimumHeight((int) (40f * density)); if (C.API_LOLLIPOP) { selectorContainer.setPadding((int) (16f * density), 0, (int) (16f * density), 0); ((LinearLayout.LayoutParams) selectorContainer.getLayoutParams()).topMargin = (int) (4f * density); } else { selectorContainer.setPadding((int) (8f * density), 0, (int) (12f * density), 0); } chanNameView = new TextView(context, null, android.R.attr.textAppearanceListItem); chanNameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, C.API_LOLLIPOP ? 14f : 16f); if (C.API_LOLLIPOP) { chanNameView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM); } else { chanNameView.setFilters(new InputFilter[] { new InputFilter.AllCaps() }); } selectorContainer.addView(chanNameView, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1)); chanSelectorIcon = new ImageView(context); chanSelectorIcon.setImageResource(ResourceUtils.getResourceId(context, R.attr.buttonDropDownDrawer, 0)); selectorContainer.addView(chanSelectorIcon, (int) (24f * density), (int) (24f * density)); ((LinearLayout.LayoutParams) chanSelectorIcon.getLayoutParams()).gravity = Gravity.CENTER_VERTICAL | Gravity.END; headerView = linearLayout; inputMethodManager = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); chans.add(new ListItem(ListItem.ITEM_DIVIDER, 0, 0, null)); int color = ResourceUtils.getColor(context, R.attr.drawerIconColor); ChanManager manager = ChanManager.getInstance(); Collection<String> availableChans = manager.getAvailableChanNames(); for (String chanName : availableChans) { ChanConfiguration configuration = ChanConfiguration.get(chanName); if (configuration.getOption(ChanConfiguration.OPTION_READ_POSTS_COUNT)) { watcherSupportSet.add(chanName); } Drawable drawable = manager.getIcon(chanName, color); chanIcons.put(chanName, drawable); chans.add( new ListItem(ListItem.ITEM_CHAN, chanName, null, null, configuration.getTitle(), 0, drawable)); } if (availableChans.size() == 1) { selectorContainer.setVisibility(View.GONE); } }
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
private void closeScanRemoteNetworkProgressDlg(final Dialog dialog, final NotifyEvent p_ntfy, final ListView lv_ipaddr, final AdapterScanAddressResultList adap, final TextView tvmsg) { final LinearLayout ll_addr = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_scan_address); final LinearLayout ll_prog = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_progress); final Button btn_scan = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_ok); final Button btn_cancel = (Button) dialog.findViewById(R.id.scan_remote_ntwk_btn_cancel); ll_addr.setVisibility(LinearLayout.VISIBLE); ll_prog.setVisibility(LinearLayout.GONE); btn_scan.setVisibility(Button.VISIBLE); btn_cancel.setVisibility(Button.VISIBLE); adap.setButtonEnabled(true);/*from www . j a v a2 s .co m*/ dialog.setOnKeyListener(null); dialog.setCancelable(true); if (p_ntfy != null) p_ntfy.notifyToListener(true, null); }
From source file:com.digi.android.wva.fragments.EndpointOptionsDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { if (mConfig == null && savedInstanceState == null) { Log.e(TAG, "mConfig is null, not showing dialog!"); return null; }//from www. ja v a2 s. c om LayoutInflater inf = getActivity().getLayoutInflater(); View v = inf.inflate(R.layout.dialog_endpoint_options, null); // Suppresses warnings, and ensures the layout exists. assert v != null; final TextView subIntervalTV = (TextView) v.findViewById(R.id.textView_interval); final TextView alarmInfoTV = (TextView) v.findViewById(R.id.alarm_info); final CheckBox subscribedCB = (CheckBox) v.findViewById(R.id.subscribedCheckbox); final CheckBox alarmCB = (CheckBox) v.findViewById(R.id.alarmCheckbox); final EditText subInterval = (EditText) v.findViewById(R.id.subscriptionInterval); final EditText alarmThreshold = (EditText) v.findViewById(R.id.alarmThreshold); final Spinner typeSpinner = (Spinner) v.findViewById(R.id.alarmTypeSpinner); final LinearLayout makeAlarmSection = (LinearLayout) v.findViewById(R.id.section_make_alarm); final LinearLayout showAlarmSection = (LinearLayout) v.findViewById(R.id.section_show_alarm); final CheckBox dcSendCB = (CheckBox) v.findViewById(R.id.dcPushCheckbox); String alarmInfo = "No alarm yet"; boolean isSubscribed = false; String endpointName = "UNKNOWN"; int sinterval = 10; boolean alarmCreated = false; double threshold = 0; int alarmtypeidx = 0; boolean isSendingToDC = false; if (savedInstanceState != null && savedInstanceState.containsKey("config")) { mConfig = savedInstanceState.getParcelable("config"); } if (mConfig != null) { endpointName = mConfig.getEndpoint(); alarmInfo = mConfig.getAlarmSummary(); if (mConfig.getSubscriptionConfig() != null) { isSubscribed = mConfig.getSubscriptionConfig().isSubscribed(); sinterval = mConfig.getSubscriptionConfig().getInterval(); isSendingToDC = mConfig.shouldBePushedToDeviceCloud(); } else { // Not subscribed; default interval value from preferences. String i = PreferenceManager.getDefaultSharedPreferences(getActivity()) .getString("pref_default_interval", "0"); try { sinterval = Integer.parseInt(i); } catch (NumberFormatException e) { Log.d(TAG, "Failed to parse default interval from preferences: " + i); sinterval = 0; } } if (mConfig.getAlarmConfig() != null) { alarmCreated = mConfig.getAlarmConfig().isCreated(); threshold = mConfig.getAlarmConfig().getThreshold(); String typestr = AlarmType.makeString(mConfig.getAlarmConfig().getType()); for (int i = 0; i < alarmTypes.length; i++) { if (alarmTypes[i].toLowerCase(Locale.US).equals(typestr)) alarmtypeidx = i; } } } // Set up event listeners on EditText and CheckBox items subscribedCB.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { subInterval.setEnabled(isChecked); subIntervalTV.setEnabled(isChecked); } }); alarmCB.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { typeSpinner.setEnabled(isChecked); alarmThreshold.setEnabled(false); // If type spinner is set to Change, we want threshold disabled again if (isChecked) { alarmThreshold.setEnabled(!shouldDisableAlarmThreshold(typeSpinner.getSelectedItemPosition())); } } }); typeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) { if (alarmCB.isChecked() && shouldDisableAlarmThreshold(position)) alarmThreshold.setEnabled(false); else if (!alarmCB.isChecked()) alarmThreshold.setEnabled(false); else alarmThreshold.setEnabled(true); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); subIntervalTV.setEnabled(false); subInterval.setEnabled(false); alarmThreshold.setEnabled(false); typeSpinner.setEnabled(false); alarmInfoTV.setText(alarmInfo); // Click checkboxes, show data depending on if subscription or alarm // has been added already if (isSubscribed) subscribedCB.performClick(); if (alarmCreated) { showAlarmSection.setVisibility(View.VISIBLE); makeAlarmSection.setVisibility(View.GONE); alarmCB.setText("Remove alarm"); } else { makeAlarmSection.setVisibility(View.VISIBLE); showAlarmSection.setVisibility(View.GONE); alarmCB.setText("Create alarm"); } dcSendCB.setChecked(isSendingToDC); subInterval.setText(Integer.toString(sinterval)); alarmThreshold.setText(Double.toString(threshold)); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.alarm_types, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); typeSpinner.setAdapter(adapter); typeSpinner.setSelection(alarmtypeidx); DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int i) { // Fetch the EndpointsAdapter's configuration for this endpoint. // (We might have gotten mConfig from the saved instance bundle) EndpointConfiguration cfg = EndpointsAdapter.getInstance() .findEndpointConfiguration(mConfig.getEndpoint()); // Set whether this endpoint's data should be pushed to Device Cloud if (cfg != null) { cfg.setPushToDeviceCloud(dcSendCB.isChecked()); } // Handle (un)subscribing if (isUnsubscribing(subscribedCB.isChecked())) { unsubscribe(mConfig.getEndpoint()); } else if (subscribedCB.isChecked()) { if (handleMakingSubscription(subInterval)) { // Subscription was successful... most likely. Log.d(TAG, "Probably subscribed to endpoint."); } else { // Invalid interval. Toast.makeText(getActivity(), getString(R.string.configure_endpoints_toast_invalid_sub_interval), Toast.LENGTH_SHORT).show(); } } // Handle adding/removing alarm as necessary if (isRemovingAlarm(alarmCB.isChecked())) { removeAlarm(mConfig.getEndpoint(), mConfig.getAlarmConfig().getType()); } else if (alarmCB.isChecked()) { Editable thresholdText = alarmThreshold.getText(); String thresholdString; if (thresholdText == null) thresholdString = ""; else thresholdString = thresholdText.toString(); double threshold; try { threshold = Double.parseDouble(thresholdString); } catch (NumberFormatException e) { Toast.makeText(getActivity(), getString(R.string.configure_endpoints_invalid_threshold), Toast.LENGTH_SHORT).show(); return; } int alarmidx = typeSpinner.getSelectedItemPosition(); if (alarmidx == -1) { // But... how? Log.wtf(TAG, "alarm type index -1 ?"); return; } String type = alarmTypes[alarmidx]; AlarmType atype = AlarmType.fromString(type); createAlarm(mConfig.getEndpoint(), atype, threshold); } dialog.dismiss(); } }; return new AlertDialog.Builder(getActivity()).setView(v).setTitle("Endpoint: " + endpointName) .setPositiveButton("Save", clickListener) .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Cancel means just dismiss the dialog. dialog.dismiss(); } }).create(); }
From source file:com.samknows.measurement.activity.SamKnowsAggregateStatViewerActivity.java
@Override public void onClick(View v) { // Toast.makeText(this,"clicked ..."+v.getId(),3000).show(); ImageView button = null;/*from w ww .j a v a 2 s . co m*/ LinearLayout l = null; int grid = 0; int testid = 0; boolean buttonfound = false; int id = v.getId(); if (id == R.id.download_header || id == R.id.btn_download_toggle) { if (total_download_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test1_grid; testid = TestResult.DOWNLOAD_TEST_ID; l = (LinearLayout) findViewById(R.id.download_content); button = (ImageView) findViewById(R.id.btn_download_toggle); } if (id == R.id.upload_header || id == R.id.btn_upload_toggle) { if (total_upload_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test2_grid; testid = TestResult.UPLOAD_TEST_ID; l = (LinearLayout) findViewById(R.id.upload_content); button = (ImageView) findViewById(R.id.btn_upload_toggle); } if (id == R.id.latency_header || id == R.id.btn_latency_toggle) { if (total_latency_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test3_grid; testid = TestResult.LATENCY_TEST_ID; l = (LinearLayout) findViewById(R.id.latency_content); button = (ImageView) findViewById(R.id.btn_latency_toggle); } if (id == R.id.packetloss_header || id == R.id.btn_packetloss_toggle) { if (total_packetloss_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test4_grid; testid = TestResult.PACKETLOSS_TEST_ID; l = (LinearLayout) findViewById(R.id.packetloss_content); button = (ImageView) findViewById(R.id.btn_packetloss_toggle); } if (id == R.id.jitter_header || id == R.id.btn_jitter_toggle) { if (total_jitter_archive_records > 0) { buttonfound = true; } grid = R.id.agggregate_test5_grid; testid = TestResult.JITTER_TEST_ID; l = (LinearLayout) findViewById(R.id.jitter_content); button = (ImageView) findViewById(R.id.btn_jitter_toggle); } // actions if (buttonfound) { if (l.getVisibility() == View.INVISIBLE) { button.setBackgroundResource(R.drawable.btn_up); button.setContentDescription(getString(R.string.close_panel)); // graphHandler1.update(); l.measure(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); target_height = l.getMeasuredHeight(); clearGrid(grid); loadDownloadGrid(testid, grid, 0, 5); l.getLayoutParams().height = 0; l.setVisibility(View.VISIBLE); ResizeAnimation animation = null; animation = new ResizeAnimation(l, target_height, 0, false); animation.setDuration(500); animation.setFillEnabled(true); animation.setFillAfter(true); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { } }); l.startAnimation(animation); } else { ResizeAnimation animation = null; int required_height = l.getMeasuredHeight(); animation = new ResizeAnimation(l, 0, target_height, false); animation.setDuration(500); animation.setFillEnabled(true); animation.setFillAfter(true); MyAnimationListener animationListener = new MyAnimationListener(); animationListener.setView(l); animation.setAnimationListener(animationListener); l.startAnimation(animation); button.setBackgroundResource(R.drawable.btn_down); button.setContentDescription(getString(R.string.open_panel)); } } }
From source file:cl.gisred.android.InspActivity.java
public void dialogBusqueda() { AlertDialog.Builder dialogBusqueda = new AlertDialog.Builder(this); dialogBusqueda.setTitle("Busqueda"); LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(R.layout.dialog_busqueda, null); dialogBusqueda.setView(v);/*from www . ja v a2 s . c o m*/ Spinner spinner = (Spinner) v.findViewById(R.id.spinnerBusqueda); final LinearLayout llBuscar = (LinearLayout) v.findViewById(R.id.llBuscar); final LinearLayout llDireccion = (LinearLayout) v.findViewById(R.id.llBuscarDir); ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, R.layout.support_simple_spinner_dropdown_item, searchArray); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); spinner.setAdapter(adapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { SpiBusqueda = position; if (position != 4) { if (llDireccion != null) llDireccion.setVisibility(View.GONE); if (llBuscar != null) llBuscar.setVisibility(View.VISIBLE); } else { if (llDireccion != null) llDireccion.setVisibility(View.VISIBLE); if (llBuscar != null) llBuscar.setVisibility(View.GONE); } } @Override public void onNothingSelected(AdapterView<?> parent) { Toast.makeText(getApplicationContext(), "Nada seleccionado", Toast.LENGTH_SHORT).show(); } }); final EditText eSearch = (EditText) v.findViewById(R.id.txtBuscar); final EditText eStreet = (EditText) v.findViewById(R.id.txtCalle); final EditText eNumber = (EditText) v.findViewById(R.id.txtNum); dialogBusqueda.setPositiveButton("Buscar", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (SpiBusqueda == 4) { txtBusqueda = new String(); if (!eStreet.getText().toString().isEmpty()) txtBusqueda = (eNumber.getText().toString().trim().isEmpty()) ? "0 " : eNumber.getText().toString().trim() + " "; txtBusqueda = txtBusqueda + eStreet.getText().toString(); } else { if (SpiBusqueda > 1) txtBusqueda = eSearch.getText().toString(); else txtBusqueda = Util.extraerNum(eSearch.getText().toString()); } if (txtBusqueda.trim().isEmpty()) { Toast.makeText(myMapView.getContext(), "Debe ingresar un valor", Toast.LENGTH_SHORT).show(); } else { // Escala de calle para busquedas por default // TODO Asignar a res values o strings iBusqScale = 4000; switch (SpiBusqueda) { case 0: callQuery(txtBusqueda, getValueByEmp("CLIENTES_XY_006.nis"), LyCLIENTES.getUrl().concat("/0")); if (LyCLIENTES.getLayers() != null && LyCLIENTES.getLayers().length > 0) iBusqScale = LyCLIENTES.getLayers()[0].getLayerServiceInfo().getMinScale(); break; case 1: callQuery(txtBusqueda, "codigo", LySED.getUrl().concat("/1")); if (LySED.getLayers() != null && LySED.getLayers().length > 1) iBusqScale = LySED.getLayers()[1].getLayerServiceInfo().getMinScale(); break; case 2: callQuery(txtBusqueda, "rotulo", LyPOSTES.getUrl().concat("/0")); if (LyPOSTES.getLayers() != null && LyPOSTES.getLayers().length > 0) iBusqScale = LyPOSTES.getLayers()[0].getLayerServiceInfo().getMinScale(); break; case 3: callQuery(txtBusqueda, "serie_medidor", LyMEDIDORES.getUrl().concat("/1")); if (LyMEDIDORES.getLayers() != null && LyMEDIDORES.getLayers().length > 1) iBusqScale = LyMEDIDORES.getLayers()[1].getLayerServiceInfo().getMinScale(); break; case 4: iBusqScale = 5000; String[] sBuscar = { eStreet.getText().toString(), eNumber.getText().toString() }; String[] sFields = { "nombre_calle", "numero" }; callQuery(sBuscar, sFields, LyDIRECCIONES.getUrl().concat("/0")); break; case 5: callQuery(txtBusqueda, new String[] { "id_equipo", "nombre" }, LyEQUIPOSLINEA.getUrl().concat("/0")); if (LyEQUIPOSLINEA.getLayers() != null && LyEQUIPOSLINEA.getLayers().length > 0) iBusqScale = LyEQUIPOSLINEA.getLayers()[0].getLayerServiceInfo().getMinScale(); break; } } } }); dialogBusqueda.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dialogBusqueda.show(); }
From source file:foam.starwisp.StarwispBuilder.java
public void Build(final StarwispActivity ctx, final String ctxname, JSONArray arr, ViewGroup parent) { if (StarwispLinearLayout.m_DisplayMetrics == null) { StarwispLinearLayout.m_DisplayMetrics = ctx.getResources().getDisplayMetrics(); }//from w ww. j av a 2s.c o m try { String type = arr.getString(0); //Log.i("starwisp","building started "+type); if (type.equals("build-fragment")) { String name = arr.getString(1); int ID = arr.getInt(2); Fragment fragment = ActivityManager.GetFragment(name); LinearLayout inner = new LinearLayout(ctx); inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); inner.setId(ID); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(ID, fragment); fragmentTransaction.commit(); parent.addView(inner); return; } if (type.equals("map")) { int ID = arr.getInt(1); LinearLayout inner = new LinearLayout(ctx); inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); inner.setId(ID); Fragment mapfrag = SupportMapFragment.newInstance(); FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction(); fragmentTransaction.add(ID, mapfrag); fragmentTransaction.commit(); parent.addView(inner); return; } if (type.equals("drawmap")) { final LinearLayout inner = new LinearLayout(ctx); inner.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); DrawableMap dm = new DrawableMap(); dm.init(arr.getInt(1), inner, (StarwispActivity) ctx, this, arr.getString(3)); parent.addView(inner); m_DMaps.put(arr.getInt(1), dm); return; } if (type.equals("linear-layout")) { StarwispLinearLayout.Build(this, ctx, ctxname, arr, parent); return; } if (type.equals("relative-layout")) { StarwispRelativeLayout.Build(this, ctx, ctxname, arr, parent); return; } if (type.equals("draggable")) { final LinearLayout v = new LinearLayout(ctx); final int id = arr.getInt(1); final String behaviour_type = arr.getString(5); v.setPadding(20, 20, 20, 10); v.setId(id); v.setOrientation(StarwispLinearLayout.BuildOrientation(arr.getString(2))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); v.setClickable(true); v.setFocusable(true); JSONArray col = arr.getJSONArray(4); v.setBackgroundResource(R.drawable.draggable); GradientDrawable drawable = (GradientDrawable) v.getBackground(); final int colour = Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)); drawable.setColor(colour); /*LayerDrawable bgDrawable = (LayerDrawable)v.getBackground(); GradientDrawable bgShape = (GradientDrawable)bgDrawable.findDrawableByLayerId(R.id.draggableshape); bgShape.setColor(colour);*/ /*v.getBackground().setColorFilter(colour, PorterDuff.Mode.MULTIPLY);*/ parent.addView(v); JSONArray children = arr.getJSONArray(6); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } // Sets a long click listener for the ImageView using an anonymous listener object that // implements the OnLongClickListener interface if (!behaviour_type.equals("drop-only") && !behaviour_type.equals("drop-only-consume")) { v.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View vv) { if (id != 99) { ClipData dragData = new ClipData( new ClipDescription("" + id, new String[] { ClipDescription.MIMETYPE_TEXT_PLAIN }), new ClipData.Item("" + id)); View.DragShadowBuilder myShadow = new MyDragShadowBuilder(v); Log.i("starwisp", "start drag id " + vv.getId() + " " + v); v.startDrag(dragData, myShadow, v, 0); v.setVisibility(View.GONE); return true; } return false; } }); } if (!behaviour_type.equals("drag-only")) { // ye gads - needed as drag/drop doesn't deal with nested targets final StarwispBuilder that = this; v.setOnDragListener(new View.OnDragListener() { public boolean onDrag(View vv, DragEvent event) { //Log.i("starwisp","on drag event happened"); final int action = event.getAction(); switch (action) { case DragEvent.ACTION_DRAG_STARTED: //Log.i("starwisp","Drag started"+v ); if (event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN)) { // returns true to indicate that the View can accept the dragged data. return true; } else { // Returns false. During the current drag and drop operation, this View will // not receive events again until ACTION_DRAG_ENDED is sent. return false; } case DragEvent.ACTION_DRAG_ENTERED: { if (that.m_LastDragHighlighted != null) { that.m_LastDragHighlighted.getBackground().setColorFilter(null); } v.getBackground().setColorFilter(0x77777777, PorterDuff.Mode.MULTIPLY); that.m_LastDragHighlighted = v; //Log.i("starwisp","Drag entered"+v ); return true; } case DragEvent.ACTION_DRAG_LOCATION: { //View dragee = (View)event.getLocalState(); //dragee.setVisibility(View.VISIBLE); //Log.i("starwisp","Drag location"+v ); return true; } case DragEvent.ACTION_DRAG_EXITED: { //Log.i("starwisp","Drag exited "+v ); v.getBackground().setColorFilter(null); return true; } case DragEvent.ACTION_DROP: { v.getBackground().setColorFilter(null); //Log.i("starwisp","Drag dropped "+v ); View otherw = (View) event.getLocalState(); //Log.i("starwisp","removing from parent "+((View)otherw.getParent()).getId()); // check we are not adding to ourself if (id != otherw.getId()) { ((ViewManager) otherw.getParent()).removeView(otherw); //Log.i("starwisp","adding to " + id); if (!behaviour_type.equals("drop-only-consume")) { v.addView(otherw); } } otherw.setVisibility(View.VISIBLE); return true; } case DragEvent.ACTION_DRAG_ENDED: { //Log.i("starwisp","Drag ended "+v ); v.getBackground().setColorFilter(null); View dragee = (View) event.getLocalState(); dragee.setVisibility(View.VISIBLE); if (event.getResult()) { //Log.i("starwisp","sucess " ); } else { //Log.i("starwisp","fail " ); } ; return true; } // An unknown action type was received. default: //Log.e("starwisp","Unknown action type received by OnDragListener."); break; } ; return true; } }); return; } } if (type.equals("frame-layout")) { FrameLayout v = new FrameLayout(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } /* if (type.equals("grid-layout")) { GridLayout v = new GridLayout(ctx); v.setId(arr.getInt(1)); v.setRowCount(arr.getInt(2)); //v.setColumnCount(arr.getInt(2)); v.setOrientation(BuildOrientation(arr.getString(3))); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); parent.addView(v); JSONArray children = arr.getJSONArray(5); for (int i=0; i<children.length(); i++) { Build(ctx,ctxname,new JSONArray(children.getString(i)), v); } return; } */ if (type.equals("scroll-view")) { HorizontalScrollView v = new HorizontalScrollView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("scroll-view-vert")) { ScrollView v = new ScrollView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); JSONArray children = arr.getJSONArray(3); for (int i = 0; i < children.length(); i++) { Build(ctx, ctxname, new JSONArray(children.getString(i)), v); } return; } if (type.equals("view-pager")) { ViewPager v = new ViewPager(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); v.setOffscreenPageLimit(3); final JSONArray items = arr.getJSONArray(3); v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) { @Override public int getCount() { return items.length(); } @Override public Fragment getItem(int position) { try { String fragname = items.getString(position); return ActivityManager.GetFragment(fragname); } catch (JSONException e) { Log.e("starwisp", "Error parsing fragment data " + e.toString()); } return null; } }); parent.addView(v); return; } if (type.equals("space")) { // Space v = new Space(ctx); (class not found runtime error??) TextView v = new TextView(ctx); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); } if (type.equals("image-view")) { ImageView v = new ImageView(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); v.setAdjustViewBounds(true); String image = arr.getString(2); if (image.startsWith("/")) { Bitmap b = BitmapCache.Load(image); if (b != null) { v.setImageBitmap(b); } } else { int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName()); v.setImageResource(id); } parent.addView(v); } if (type.equals("image-button")) { ImageButton v = new ImageButton(ctx); v.setId(arr.getInt(1)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); String image = arr.getString(2); if (image.startsWith("/")) { v.setImageBitmap(BitmapCache.Load(image)); } else { int id = ctx.getResources().getIdentifier(image, "drawable", ctx.getPackageName()); v.setImageResource(id); } final String fn = arr.getString(4); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Callback(ctx, ctxname, v.getId()); } }); v.setAdjustViewBounds(true); v.setScaleType(ImageView.ScaleType.CENTER_INSIDE); parent.addView(v); } if (type.equals("text-view")) { TextView v = new TextView(ctx); v.setId(arr.getInt(1)); v.setText(Html.fromHtml(arr.getString(2)), BufferType.SPANNABLE); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setLinkTextColor(0xff00aa00); // uncomment all this to get hyperlinks to work in text... // should make this an option of course //v.setClickable(true); // make links //v.setMovementMethod(LinkMovementMethod.getInstance()); //v.setEnabled(true); // go to browser /*v.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View vv, MotionEvent event) { return false; } };*/ if (arr.length() > 5) { if (arr.getString(5).equals("left")) { v.setGravity(Gravity.LEFT); } else { if (arr.getString(5).equals("fill")) { v.setGravity(Gravity.FILL); } else { v.setGravity(Gravity.CENTER); } } } else { v.setGravity(Gravity.CENTER); } v.setTypeface(((StarwispActivity) ctx).m_Typeface); parent.addView(v); } if (type.equals("debug-text-view")) { TextView v = (TextView) ctx.getLayoutInflater().inflate(R.layout.debug_text, null); // v.setBackgroundResource(R.color.black); v.setId(arr.getInt(1)); // v.setText(Html.fromHtml(arr.getString(2))); // v.setTextColor(R.color.white); // v.setTextSize(arr.getInt(3)); // v.setMovementMethod(LinkMovementMethod.getInstance()); // v.setMaxLines(10); // v.setVerticalScrollBarEnabled(true); // v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); //v.setMovementMethod(new ScrollingMovementMethod()); /* if (arr.length()>5) { if (arr.getString(5).equals("left")) { v.setGravity(Gravity.LEFT); } else { if (arr.getString(5).equals("fill")) { v.setGravity(Gravity.FILL); } else { v.setGravity(Gravity.CENTER); } } } else { v.setGravity(Gravity.LEFT); } v.setTypeface(((StarwispActivity)ctx).m_Typeface);*/ parent.addView(v); } if (type.equals("web-view")) { WebView v = new WebView(ctx); v.setId(arr.getInt(1)); v.setVerticalScrollBarEnabled(false); v.loadData(arr.getString(2), "text/html", "utf-8"); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); parent.addView(v); } if (type.equals("edit-text")) { final EditText v = new EditText(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setGravity(Gravity.LEFT | Gravity.TOP); String inputtype = arr.getString(4); if (inputtype.equals("text")) { //v.setInputType(InputType.TYPE_CLASS_TEXT); } else if (inputtype.equals("numeric")) { v.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED); } else if (inputtype.equals("email")) { v.setInputType(InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS); } v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(5))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(5); //v.setSingleLine(true); v.addTextChangedListener(new TextWatcher() { public void afterTextChanged(Editable s) { CallbackArgs(ctx, ctxname, v.getId(), "\"" + s.toString() + "\""); } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } }); parent.addView(v); } if (type.equals("button")) { Button v = new Button(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(5); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Callback(ctx, ctxname, v.getId()); } }); parent.addView(v); } if (type.equals("colour-button")) { Button v = new Button(ctx); v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); JSONArray col = arr.getJSONArray(6); v.getBackground().setColorFilter( Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)), PorterDuff.Mode.MULTIPLY); final String fn = arr.getString(5); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { Callback(ctx, ctxname, v.getId()); } }); parent.addView(v); } if (type.equals("toggle-button")) { ToggleButton v = new ToggleButton(ctx); if (arr.getString(5).equals("fancy")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_fancy, null); } if (arr.getString(5).equals("yes")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_yes, null); } if (arr.getString(5).equals("maybe")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_maybe, null); } if (arr.getString(5).equals("no")) { v = (ToggleButton) ctx.getLayoutInflater().inflate(R.layout.toggle_button_no, null); } v.setId(arr.getInt(1)); v.setText(arr.getString(2)); v.setTextSize(arr.getInt(3)); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(4))); v.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(6); v.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, v.getId(), arg); } }); parent.addView(v); } if (type.equals("seek-bar")) { SeekBar v = new SeekBar(ctx); v.setId(arr.getInt(1)); v.setMax(arr.getInt(2)); v.setProgress(arr.getInt(2) / 2); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); final String fn = arr.getString(4); v.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar v, int a, boolean s) { CallbackArgs(ctx, ctxname, v.getId(), Integer.toString(a)); } public void onStartTrackingTouch(SeekBar v) { } public void onStopTrackingTouch(SeekBar v) { } }); parent.addView(v); } if (type.equals("spinner")) { Spinner v = new Spinner(ctx); final int wid = arr.getInt(1); v.setId(wid); final JSONArray items = arr.getJSONArray(2); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3))); v.setMinimumWidth(100); // stops tiny buttons ArrayList<String> spinnerArray = new ArrayList<String>(); for (int i = 0; i < items.length(); i++) { spinnerArray.add(items.getString(i)); } ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item, spinnerArray) { public View getView(int position, View convertView, ViewGroup parent) { View v = super.getView(position, convertView, parent); ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface); return v; } }; spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout); v.setAdapter(spinnerArrayAdapter); v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> a, View v, int pos, long id) { CallbackArgs(ctx, ctxname, wid, "" + pos); } public void onNothingSelected(AdapterView<?> v) { } }); parent.addView(v); } if (type.equals("nomadic")) { final int wid = arr.getInt(1); NomadicSurfaceView v = new NomadicSurfaceView(ctx, wid); v.setId(wid); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); Log.e("starwisp", "built the thing"); parent.addView(v); Log.e("starwisp", "addit to the view"); } if (type.equals("canvas")) { StarwispCanvas v = new StarwispCanvas(ctx); final int wid = arr.getInt(1); v.setId(wid); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); v.SetDrawList(arr.getJSONArray(3)); parent.addView(v); } if (type.equals("camera-preview")) { PictureTaker pt = new PictureTaker(); CameraPreview v = new CameraPreview(ctx, pt); final int wid = arr.getInt(1); v.setId(wid); v.setLayoutParams(BuildLayoutParams(arr.getJSONArray(2))); parent.addView(v); Log.i("starwisp", "in camera-preview..."); List<List<String>> info = v.mPictureTaker.GetInfo(); // can't find a way to do this via a callback yet String arg = "'("; for (List<String> e : info) { arg += "(" + e.get(0) + " " + e.get(1) + ")"; //Log.i("starwisp","converting prop "+arg); } arg += ")"; m_Scheme.eval("(set! camera-properties " + arg + ")"); } if (type.equals("button-grid")) { LinearLayout horiz = new LinearLayout(ctx); final int id = arr.getInt(1); final String buttontype = arr.getString(2); horiz.setId(id); horiz.setOrientation(LinearLayout.HORIZONTAL); parent.addView(horiz); int height = arr.getInt(3); int textsize = arr.getInt(4); LayoutParams lp = BuildLayoutParams(arr.getJSONArray(5)); JSONArray buttons = arr.getJSONArray(6); int count = buttons.length(); int vertcount = 0; LinearLayout vert = null; for (int i = 0; i < count; i++) { JSONArray button = buttons.getJSONArray(i); if (vertcount == 0) { vert = new LinearLayout(ctx); vert.setId(0); vert.setOrientation(LinearLayout.VERTICAL); horiz.addView(vert); } vertcount = (vertcount + 1) % height; if (buttontype.equals("button")) { Button b = new Button(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(6); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t"); } }); vert.addView(b); } else if (buttontype.equals("toggle")) { ToggleButton b = new ToggleButton(ctx); b.setId(button.getInt(0)); b.setText(button.getString(1)); b.setTextSize(textsize); b.setLayoutParams(lp); b.setTypeface(((StarwispActivity) ctx).m_Typeface); final String fn = arr.getString(6); b.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String arg = "#f"; if (((ToggleButton) v).isChecked()) arg = "#t"; CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg); } }); vert.addView(b); } } } } catch (JSONException e) { Log.e("starwisp", "Error parsing [" + arr.toString() + "] " + e.toString()); } //Log.i("starwisp","building ended"); }