List of usage examples for android.widget ListView setScrollingCacheEnabled
public void setScrollingCacheEnabled(boolean enabled)
From source file:org.jraf.android.hellomundo.app.pickwebcam.PickWebcamListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View res = super.onCreateView(inflater, container, savedInstanceState); // Add 'random' item ListView listView = (ListView) res.findViewById(android.R.id.list); setListAdapter(mAdapter);/*from www .jav a2 s . c o m*/ mAdapter.setListView(listView); listView.addHeaderView(getHeaderView(listView), null, true); // Disable dividers since they are handled manually in cell layouts listView.setDividerHeight(0); // Disable this optimization because this cause problems on dividers in hdpi listView.setScrollingCacheEnabled(false); // Layout animation listView.setLayoutAnimation(AnimationUtils.loadLayoutAnimation(getActivity(), R.anim.listview_layout)); return res; }
From source file:io.jari.geenstijl.Blog.java
void initUI(final Artikel[] artikelen, final boolean doSwitchState) { final PullToRefreshLayout mPullToRefreshLayout = (PullToRefreshLayout) findViewById(R.id.ptr_layout); runOnUiThread(new Runnable() { public void run() { ListView siteSwitch = (ListView) findViewById(R.id.site_switcher); String domain = getSharedPreferences("geenstijl", 0).getString("gsdomain", "www.geenstijl.nl"); if (domain.equals("www.geenstijl.nl")) { actionBar.setTitle("GeenStijl"); siteSwitch.setItemChecked(0, true); } else { actionBar.setTitle("GeenStijl.TV"); siteSwitch.setItemChecked(1, true); }/*www . java 2s. co m*/ final ListView show = (ListView) findViewById(R.id.show); if (showTopPadding == 0) showTopPadding = show.getPaddingTop(); show.setScrollingCacheEnabled(false); show.setAdapter(new ArtikelAdapter(Blog.this, 0, artikelen)); //#HOLOYOLO if (Build.VERSION.SDK_INT >= 19) { SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); show.setPadding(0, showTopPadding + config.getPixelInsetTop(true), 0, 0); } //hiding the actionbar when scrolling show.setOnScrollListener(new AbsListView.OnScrollListener() { int mLastFirstVisibleItem = 0; public void onScrollStateChanged(AbsListView view, int scrollState) { } public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { if (view.getId() == show.getId()) { final int currentFirstVisibleItem = show.getFirstVisiblePosition(); if (currentFirstVisibleItem > mLastFirstVisibleItem && actionBar.isShowing()) { enableImmersive(true, show); } else if (currentFirstVisibleItem < mLastFirstVisibleItem && !actionBar.isShowing()) { enableImmersive(false, show); } mLastFirstVisibleItem = currentFirstVisibleItem; } } }); //footer if (show.getAdapter().getClass() != HeaderViewListAdapter.class) { //check if footer is present, if not, add it View footer = getLayoutInflater().inflate(R.layout.meerrr, null); final View button = footer.findViewById(R.id.more); if (Build.VERSION.SDK_INT >= 19) { ViewGroup.LayoutParams params = button.getLayoutParams(); SystemBarTintManager.SystemBarConfig config = tintManager.getConfig(); ((ViewGroup.MarginLayoutParams) params).bottomMargin = config.getPixelInsetBottom(); } button.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { button.setEnabled(false); mPullToRefreshLayout.setRefreshing(true); enableImmersive(false, show); forceNoImmersive = true; new Thread(new Runnable() { public void run() { try { final Artikel[] artikelen2 = API.getArticles(true, true, getApplicationContext()); runOnUiThread(new Runnable() { public void run() { ListView show = (ListView) findViewById(R.id.show); //java is such a beautiful language *cough* ArtikelAdapter artikelAdapter = (ArtikelAdapter) ((HeaderViewListAdapter) show .getAdapter()).getWrappedAdapter(); artikelAdapter.update(artikelen2); mPullToRefreshLayout.setRefreshComplete(); button.setVisibility(View.GONE); forceNoImmersive = false; } }); } catch (final Exception e) { e.printStackTrace(); runOnUiThread(new Runnable() { public void run() { button.setEnabled(true); mPullToRefreshLayout.setRefreshComplete(); forceNoImmersive = false; Crouton.makeText(Blog.this, e.getLocalizedMessage() == null ? "Onbekende fout" : e.getLocalizedMessage(), Style.ALERT).show(); } }); } } }).start(); } }); show.addFooterView(footer); } //grreat success! if (doSwitchState) switchState(STATE_SHOW); else mPullToRefreshLayout.setRefreshComplete(); } }); }
From source file:com.sentaroh.android.Utilities.ContextMenu.CustomContextMenuFragment.java
private void initViewWidget() { if (DEBUG_ENABLE) Log.v(APPLICATION_TAG, "initViewWidget"); // CommonDialog.setDlgBoxSizeCompact(mDialog); LinearLayout dlg_ll = new LinearLayout(getActivity()); dlg_ll.setOrientation(LinearLayout.VERTICAL); TextView dlg_tv = new TextView(getActivity()); dlg_tv.setBackgroundColor(Color.WHITE); dlg_tv.setTextColor(Color.BLACK); // dlg_tv.setTextSize(32); dlg_tv.setGravity(android.view.Gravity.CENTER_VERTICAL | android.view.Gravity.CENTER_HORIZONTAL); ListView dlg_lv = new ListView(getActivity()); dlg_lv.setBackgroundColor(Color.WHITE); dlg_ll.addView(dlg_tv);/*w w w .j a v a 2 s . c o m*/ dlg_ll.addView(dlg_lv); mDialog.setContentView(dlg_ll); if (mDialogTitle.length() != 0) { dlg_tv.setText(mDialogTitle); dlg_tv.setVisibility(TextView.VISIBLE); } else dlg_tv.setVisibility(TextView.GONE); dlg_lv.setAdapter(mMenuAdapter); dlg_lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> items, View view, int idx, long id) { CustomContextMenuItem item = (CustomContextMenuItem) mMenuAdapter.getItem(idx); if (item.menu_enabled) { if (idx < mClickHandler.size()) { mClickHandler.get(idx).onClick(item.text); } mFragment.dismiss(); } } }); dlg_lv.setScrollingCacheEnabled(false); dlg_lv.setScrollbarFadingEnabled(false); // int[] colors = {0, 0xFFFF0000, 0}; // red for the example // lv.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors)); dlg_lv.setDividerHeight(0); }
From source file:com.fsck.k9.activity.Accounts.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); if (!K9.isHideSpecialAccounts()) { createSpecialAccounts();//from www .j ava 2s. c om } Account[] accounts = Preferences.getPreferences(this).getAccounts(); Intent intent = getIntent(); //onNewIntent(intent); // see if we should show the welcome message if (ACTION_IMPORT_SETTINGS.equals(intent.getAction())) { onImport(); } else if (accounts.length < 1) { WelcomeMessage.showWelcomeMessage(this); finish(); return; } if (UpgradeDatabases.actionUpgradeDatabases(this, intent)) { finish(); return; } boolean startup = intent.getBooleanExtra(EXTRA_STARTUP, true); if (startup && K9.startIntegratedInbox() && !K9.isHideSpecialAccounts()) { onOpenAccount(mUnifiedInboxAccount); finish(); return; } else if (startup && accounts.length == 1 && onOpenAccount(accounts[0])) { finish(); return; } mActionBar = getSupportActionBar(); initializeActionBar(); //setContentView(R.layout.accounts); ListView listView = getListView(); listView.setOnItemClickListener(this); listView.setItemsCanFocus(false); listView.setScrollingCacheEnabled(false); registerForContextMenu(listView); if (icicle != null && icicle.containsKey(SELECTED_CONTEXT_ACCOUNT)) { String accountUuid = icicle.getString("selectedContextAccount"); mSelectedContextAccount = Preferences.getPreferences(this).getAccount(accountUuid); } restoreAccountStats(icicle); mHandler.setViewTitle(); // Handle activity restarts because of a configuration change (e.g. rotating the screen) mNonConfigurationInstance = (NonConfigurationInstance) getLastCustomNonConfigurationInstance(); if (mNonConfigurationInstance != null) { mNonConfigurationInstance.restore(this); } ChangeLog cl = new ChangeLog(this); if (cl.isFirstRun()) { cl.getLogDialog().show(); } }
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 ww w .j a v a2 s .c o 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
public void scanRemoteNetworkDlg(final NotifyEvent p_ntfy, String port_number, boolean scan_start) { //??/*from w w w . java2s . c om*/ final Dialog dialog = new Dialog(mContext); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(false); dialog.setContentView(R.layout.scan_remote_ntwk_dlg); LinearLayout ll_dlg_view = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_dlg_view); ll_dlg_view.setBackgroundColor(mGp.themeColorList.dialog_msg_background_color); final LinearLayout title_view = (LinearLayout) dialog.findViewById(R.id.scan_remote_ntwk_title_view); final TextView title = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_title); title_view.setBackgroundColor(mGp.themeColorList.dialog_title_background_color); title.setTextColor(mGp.themeColorList.text_color_dialog_title); 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); final TextView tvmsg = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_msg); final TextView tv_result = (TextView) dialog.findViewById(R.id.scan_remote_ntwk_scan_result_title); tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_press_scan_btn)); tv_result.setVisibility(TextView.GONE); final String from = CommonUtilities.getLocalIpAddress(); String subnet = from.substring(0, from.lastIndexOf(".")); String subnet_o1, subnet_o2, subnet_o3; subnet_o1 = subnet.substring(0, subnet.indexOf(".")); subnet_o2 = subnet.substring(subnet.indexOf(".") + 1, subnet.lastIndexOf(".")); subnet_o3 = subnet.substring(subnet.lastIndexOf(".") + 1, subnet.length()); final EditText baEt1 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o1); final EditText baEt2 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o2); final EditText baEt3 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o3); final EditText baEt4 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_begin_address_o4); final EditText eaEt4 = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_end_address_o4); baEt1.setText(subnet_o1); baEt2.setText(subnet_o2); baEt3.setText(subnet_o3); baEt4.setText("1"); baEt4.setSelection(1); eaEt4.setText("254"); baEt4.requestFocus(); final CheckedTextView ctv_use_port_number = (CheckedTextView) dialog .findViewById(R.id.scan_remote_ntwk_ctv_use_port); final EditText et_port_number = (EditText) dialog.findViewById(R.id.scan_remote_ntwk_port_number); CommonDialog.setDlgBoxSizeLimit(dialog, true); if (port_number.equals("")) { et_port_number.setEnabled(false); ctv_use_port_number.setChecked(false); } else { et_port_number.setEnabled(true); et_port_number.setText(port_number); ctv_use_port_number.setChecked(true); } ctv_use_port_number.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ctv_use_port_number.toggle(); boolean isChecked = ctv_use_port_number.isChecked(); et_port_number.setEnabled(isChecked); } }); final NotifyEvent ntfy_lv_click = new NotifyEvent(mContext); ntfy_lv_click.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { dialog.dismiss(); p_ntfy.notifyToListener(true, o); } @Override public void negativeResponse(Context c, Object[] o) { } }); final ArrayList<ScanAddressResultListItem> ipAddressList = new ArrayList<ScanAddressResultListItem>(); // ScanAddressResultListItem li=new ScanAddressResultListItem(); // li.server_name=mContext.getString(R.string.msgs_ip_address_no_address); // ipAddressList.add(li); final ListView lv = (ListView) dialog.findViewById(R.id.scan_remote_ntwk_scan_result_list); final AdapterScanAddressResultList adap = new AdapterScanAddressResultList(mContext, R.layout.scan_address_result_list_item, ipAddressList, ntfy_lv_click); lv.setAdapter(adap); lv.setScrollingCacheEnabled(false); lv.setScrollbarFadingEnabled(false); //SCAN? btn_scan.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { ipAddressList.clear(); NotifyEvent ntfy = new NotifyEvent(mContext); ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { if (ipAddressList.size() < 1) { tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_not_detected)); tv_result.setVisibility(TextView.GONE); } else { tvmsg.setText(mContext.getString(R.string.msgs_scan_ip_address_select_detected_host)); tv_result.setVisibility(TextView.VISIBLE); } // adap.clear(); // for (int i=0;i<ipAddressList.size();i++) // adap.add(ipAddressList.get(i)); } @Override public void negativeResponse(Context c, Object[] o) { } }); if (auditScanAddressRangeValue(dialog)) { tv_result.setVisibility(TextView.GONE); String ba1 = baEt1.getText().toString(); String ba2 = baEt2.getText().toString(); String ba3 = baEt3.getText().toString(); String ba4 = baEt4.getText().toString(); String ea4 = eaEt4.getText().toString(); String subnet = ba1 + "." + ba2 + "." + ba3; int begin_addr = Integer.parseInt(ba4); int end_addr = Integer.parseInt(ea4); scanRemoteNetwork(dialog, lv, adap, ipAddressList, subnet, begin_addr, end_addr, ntfy); } else { //error } } }); //CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); p_ntfy.notifyToListener(false, null); } }); // Cancel? dialog.setOnCancelListener(new Dialog.OnCancelListener() { @Override public void onCancel(DialogInterface arg0) { btn_cancel.performClick(); } }); dialog.show(); if (scan_start) btn_scan.performClick(); }
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
public void setRemoteDir(final String remurl, final String curdir, final String p_dir, final NotifyEvent p_ntfy) { final ArrayList<TreeFilelistItem> rows = new ArrayList<TreeFilelistItem>(); NotifyEvent ntfy = new NotifyEvent(mContext); // set thread response ntfy.setListener(new NotifyEventListener() { @Override/*from w ww . j av a 2 s. c o m*/ public void positiveResponse(Context c, Object[] o) { @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_select_remote_dir)); subtitle.setText(mContext.getString(R.string.msgs_current_dir) + "/" + remurl); // if (rows.size()<1) { // TextView dlg_msg=(TextView)dialog.findViewById(R.id.item_select_list_dlg_msg); // dlg_msg.setText(msgs_dir_empty); // dlg_msg.setVisibility(TextView.VISIBLE); // } final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn); // 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, true, false); // tfa.setNotifyOnChange(true); tfa.setDataList(rows); lv.setAdapter(tfa); lv.setScrollingCacheEnabled(false); lv.setScrollbarFadingEnabled(false); lv.setFastScrollEnabled(true); if (p_dir.length() != 0) for (int i = 0; i < tfa.getDataItemCount(); i++) { if (tfa.getDataItem(i).getName().equals(p_dir)) lv.setSelection(i); } 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); if (tfa.getDataItem(t_pos).isChecked()) { ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_unselect_this_entry) + " " + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName()) .setOnClickListener(new CustomContextMenuOnClickListener() { @Override public void onClick(CharSequence menuTitle) { final TreeFilelistItem tfi = tfa.getDataItem(t_pos); if (tfi.getName().startsWith("---")) return; tfa.setDataItemIsUnselected(t_pos); btn_ok.setEnabled(false); } }); } else { ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_select_this_entry) + " " + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName()) .setOnClickListener(new CustomContextMenuOnClickListener() { @Override public void onClick(CharSequence menuTitle) { final TreeFilelistItem tfi = tfa.getDataItem(t_pos); if (tfi.getName().startsWith("---")) return; tfa.setDataItemIsSelected(t_pos); btn_ok.setEnabled(true); } }); } ccMenu.createMenu(); return false; } }); NotifyEvent ctv_ntfy = new NotifyEvent(mContext); // set file list thread response listener ctv_ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { if (o != null) { int pos = (Integer) o[0]; if (tfa.getDataItem(pos).isChecked()) btn_ok.setEnabled(true); } } @Override public void negativeResponse(Context c, Object[] o) { btn_ok.setEnabled(false); for (int i = 0; i < tfa.getDataItemCount(); i++) { if (tfa.getDataItem(i).isChecked()) { btn_ok.setEnabled(true); break; } } } }); tfa.setCbCheckListener(ctv_ntfy); //OK? btn_ok.setEnabled(false); btn_ok.setVisibility(Button.VISIBLE); btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String sel = ""; for (int i = 0; i < tfa.getCount(); i++) { if (tfa.getDataItem(i).isChecked() && !tfa.getDataItem(i).getName() .equals(mContext.getString(R.string.msgs_dir_empty))) { if (tfa.getDataItem(i).getPath().length() == 1) sel = tfa.getDataItem(i).getName(); else sel = tfa.getDataItem(i).getPath().substring(1, tfa.getDataItem(i).getPath().length()) + tfa.getDataItem(i).getName(); break; } } dialog.dismiss(); p_ntfy.notifyToListener(true, new Object[] { sel }); } }); //CANCEL? final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn); btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); p_ntfy.notifyToListener(false, 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, curdir, ntfy, true); return; }
From source file:com.sentaroh.android.SMBSync2.SyncTaskUtility.java
public void selectLocalDirDlg(final String url, final String dir, String p_dir, final NotifyEvent p_ntfy) { //??/*from w ww .ja va 2 s. c o m*/ 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_select_local_dir)); subtitle.setText(mContext.getString(R.string.msgs_current_dir) + url + dir); final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn); // if (rows.size()<=2) // ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer)) // .setVisibility(TextView.VISIBLE); CommonDialog.setDlgBoxSizeLimit(dialog, true); ListView lv = (ListView) dialog.findViewById(android.R.id.list); final TreeFilelistAdapter tfa = new TreeFilelistAdapter(mContext, true, false); lv.setAdapter(tfa); ArrayList<TreeFilelistItem> tfl = createLocalFilelist(true, url, dir); if (tfl.size() < 1) tfl.add(new TreeFilelistItem(mContext.getString(R.string.msgs_dir_empty))); tfa.setDataList(tfl); lv.setScrollingCacheEnabled(false); lv.setScrollbarFadingEnabled(false); lv.setFastScrollEnabled(true); if (p_dir.length() != 0) for (int i = 0; i < tfa.getDataItemCount(); i++) { if (tfa.getDataItem(i).getName().equals(p_dir)) lv.setSelection(i); } 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, url, 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); if (tfa.getDataItem(t_pos).isChecked()) { ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_select_this_entry) + " " + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName()) .setOnClickListener(new CustomContextMenuOnClickListener() { @Override public void onClick(CharSequence menuTitle) { final TreeFilelistItem tfi = tfa.getDataItem(t_pos); if (tfi.getName().startsWith("---")) return; tfa.setDataItemIsUnselected(t_pos); if (tfa.isDataItemIsSelected()) btn_ok.setEnabled(true); else btn_ok.setEnabled(false); } }); } else { ccMenu.addMenuItem(mContext.getString(R.string.msgs_file_select_select_this_entry) + " " + tfa.getDataItem(t_pos).getPath() + tfa.getDataItem(t_pos).getName()) .setOnClickListener(new CustomContextMenuOnClickListener() { @Override public void onClick(CharSequence menuTitle) { final TreeFilelistItem tfi = tfa.getDataItem(t_pos); if (tfi.getName().startsWith("---")) return; tfa.setDataItemIsSelected(t_pos); btn_ok.setEnabled(true); } }); } ccMenu.createMenu(); return false; } }); NotifyEvent ctv_ntfy = new NotifyEvent(mContext); ctv_ntfy.setListener(new NotifyEventListener() { @Override public void positiveResponse(Context c, Object[] o) { if (o != null) { int pos = (Integer) o[0]; if (tfa.getDataItem(pos).isChecked()) btn_ok.setEnabled(true); } } @Override public void negativeResponse(Context c, Object[] o) { btn_ok.setEnabled(false); for (int i = 0; i < tfa.getDataItemCount(); i++) { if (tfa.getDataItem(i).isChecked()) { btn_ok.setEnabled(true); break; } } } }); tfa.setCbCheckListener(ctv_ntfy); //OK? btn_ok.setEnabled(false); btn_ok.setVisibility(Button.VISIBLE); btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { String sel = ""; for (int i = 0; i < tfa.getCount(); i++) { if (tfa.getDataItem(i).isChecked() && !tfa.getDataItem(i).getName().equals(mContext.getString(R.string.msgs_dir_empty))) { if (tfa.getDataItem(i).getPath().length() == 1) sel = tfa.getDataItem(i).getName(); else sel = tfa.getDataItem(i).getPath().substring(1, tfa.getDataItem(i).getPath().length()) + tfa.getDataItem(i).getName(); break; } } if (sel.equals("")) { } dialog.dismiss(); p_ntfy.notifyToListener(true, new Object[] { sel }); } }); //CANCEL? final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn); btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); p_ntfy.notifyToListener(false, 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 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 ww.j a v a 2s. c o m 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
public void selectRemoteShareDlg(final String remurl, String remdir, final NotifyEvent p_ntfy) { NotifyEvent ntfy = new NotifyEvent(mContext); // set thread response ntfy.setListener(new NotifyEventListener() { @Override/* w ww . j a v a2s . c om*/ public void positiveResponse(Context c, Object[] o) { final ArrayList<String> rows = new ArrayList<String>(); @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() && !rfl.get(i).getName().endsWith("$")) // !rfl.get(i).getName().startsWith("IPC$")) rows.add(rfl.get(i).getName().replaceAll("/", "")); } boolean wk_list_empty = false; if (rows.size() < 1) { wk_list_empty = true; rows.add(mContext.getString(R.string.msgs_dir_empty)); } final boolean list_empty = wk_list_empty; Collections.sort(rows, String.CASE_INSENSITIVE_ORDER); //?? 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_select_remote_share)); subtitle.setVisibility(TextView.GONE); // if (rows.size()<=2) // ((TextView)dialog.findViewById(R.id.item_select_list_dlg_spacer)) // .setVisibility(TextView.VISIBLE); final Button btn_cancel = (Button) dialog.findViewById(R.id.item_select_list_dlg_cancel_btn); final Button btn_ok = (Button) dialog.findViewById(R.id.item_select_list_dlg_ok_btn); btn_ok.setEnabled(false); CommonDialog.setDlgBoxSizeLimit(dialog, false); final ListView lv = (ListView) dialog.findViewById(android.R.id.list); if (!list_empty) { lv.setAdapter( new ArrayAdapter<String>(mContext, R.layout.custom_simple_list_item_checked, rows)); // android.R.layout.simple_list_item_checked,rows)); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); } else { lv.setAdapter(new ArrayAdapter<String>(mContext, R.layout.simple_list_item_1o, rows)); } lv.setScrollingCacheEnabled(false); lv.setScrollbarFadingEnabled(false); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> items, View view, int idx, long id) { if (rows.get(idx).startsWith("---")) return; if (!list_empty) btn_ok.setEnabled(true); } }); //CANCEL? btn_cancel.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); p_ntfy.notifyToListener(false, null); } }); //OK? btn_ok.setVisibility(Button.VISIBLE); btn_ok.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { dialog.dismiss(); SparseBooleanArray checked = lv.getCheckedItemPositions(); for (int i = 0; i <= rows.size(); i++) { if (checked.get(i) == true) { p_ntfy.notifyToListener(true, new Object[] { rows.get(i) }); break; } } } }); // 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, false); }