List of usage examples for android.widget ListView setTextFilterEnabled
public void setTextFilterEnabled(boolean textFilterEnabled)
From source file:com.gimranov.zandy.app.AttachmentActivity.java
/** Called when the activity is first created. */ @Override/*from w w w. j a v a 2 s . c om*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); tmpFiles = new ArrayList<File>(); db = new Database(this); /* Get the incoming data from the calling activity */ final String itemKey = getIntent().getStringExtra("com.gimranov.zandy.app.itemKey"); Item item = Item.load(itemKey, db); this.item = item; if (item == null) { Log.e(TAG, "AttachmentActivity started without itemKey; finishing."); finish(); return; } this.setTitle(getResources().getString(R.string.attachments_for_item, item.getTitle())); ArrayList<Attachment> rows = Attachment.forItem(item, db); /* * We use the standard ArrayAdapter, passing in our data as a Attachment. * Since it's no longer a simple TextView, we need to override getView, but * we can do that anonymously. */ setListAdapter(new ArrayAdapter<Attachment>(this, R.layout.list_attach, rows) { @Override public View getView(int position, View convertView, ViewGroup parent) { View row; // We are reusing views, but we need to initialize it if null if (null == convertView) { LayoutInflater inflater = getLayoutInflater(); row = inflater.inflate(R.layout.list_attach, null); } else { row = convertView; } ImageView tvType = (ImageView) row.findViewById(R.id.attachment_type); TextView tvSummary = (TextView) row.findViewById(R.id.attachment_summary); Attachment att = getItem(position); Log.d(TAG, "Have an attachment: " + att.title + " fn:" + att.filename + " status:" + att.status); tvType.setImageResource(Item.resourceForType(att.getType())); try { Log.d(TAG, att.content.toString(4)); } catch (JSONException e) { Log.e(TAG, "JSON parse exception when reading attachment content", e); } if (att.getType().equals("note")) { String note = att.content.optString("note", ""); if (note.length() > 40) { note = note.substring(0, 40); } tvSummary.setText(note); } else { StringBuffer status = new StringBuffer(getResources().getString(R.string.status)); if (att.status == Attachment.AVAILABLE) status.append(getResources().getString(R.string.attachment_zfs_available)); else if (att.status == Attachment.LOCAL) status.append(getResources().getString(R.string.attachment_zfs_local)); else status.append(getResources().getString(R.string.attachment_unknown)); tvSummary.setText(att.title + " " + status.toString()); } return row; } }); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemLongClickListener(new OnItemLongClickListener() { // Warning here because Eclipse can't tell whether my ArrayAdapter is // being used with the correct parametrization. @SuppressWarnings("unchecked") public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // If we have a click on an entry, show its note ArrayAdapter<Attachment> adapter = (ArrayAdapter<Attachment>) parent.getAdapter(); Attachment row = adapter.getItem(position); if (row.content.has("note")) { Log.d(TAG, "Trying to start note view activity for: " + row.key); Intent i = new Intent(getBaseContext(), NoteActivity.class); i.putExtra("com.gimranov.zandy.app.attKey", row.key);//row.content.optString("note", "")); startActivity(i); } return true; } }); lv.setOnItemClickListener(new OnItemClickListener() { // Warning here because Eclipse can't tell whether my ArrayAdapter is // being used with the correct parametrization. @SuppressWarnings("unchecked") public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // If we have a long click on an entry, do something... ArrayAdapter<Attachment> adapter = (ArrayAdapter<Attachment>) parent.getAdapter(); Attachment row = adapter.getItem(position); String url = (row.url != null && !row.url.equals("")) ? row.url : row.content.optString("url"); if (!row.getType().equals("note")) { Bundle b = new Bundle(); b.putString("title", row.title); b.putString("attachmentKey", row.key); b.putString("content", url); SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); int linkMode = row.content.optInt("linkMode", Attachment.MODE_IMPORTED_URL); if (settings.getBoolean("webdav_enabled", false)) b.putString("mode", "webdav"); else b.putString("mode", "zfs"); if (linkMode == Attachment.MODE_IMPORTED_FILE || linkMode == Attachment.MODE_IMPORTED_URL) { loadFileAttachment(b); } else { AttachmentActivity.this.b = b; showDialog(DIALOG_CONFIRM_NAVIGATE); } } if (row.getType().equals("note")) { Bundle b = new Bundle(); b.putString("attachmentKey", row.key); b.putString("itemKey", itemKey); b.putString("content", row.content.optString("note", "")); removeDialog(DIALOG_NOTE); AttachmentActivity.this.b = b; showDialog(DIALOG_NOTE); } return; } }); }
From source file:com.googlecode.networklog.LogFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { MyLog.d("[LogFragment] onCreateView"); LinearLayout layout = new LinearLayout(getActivity().getApplicationContext()); layout.setOrientation(LinearLayout.VERTICAL); ListView listView = new ListView(getActivity().getApplicationContext()); listView.setAdapter(adapter);// w ww. ja v a 2 s . c o m listView.setTextFilterEnabled(true); listView.setFastScrollEnabled(true); listView.setSmoothScrollbarEnabled(false); listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_NORMAL); listView.setStackFromBottom(true); listView.setOnItemClickListener(new CustomOnItemClickListener()); layout.addView(listView); registerForContextMenu(listView); startUpdater(); return layout; }
From source file:org.solovyev.android.messenger.BaseListFragment.java
protected void fillListView(@Nonnull ListView lv, @Nonnull Context context) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ECLAIR) { lv.setScrollbarFadingEnabled(true); }//from w w w .j av a2 s.c o m lv.setBackgroundDrawable(null); lv.setCacheColorHint(Color.TRANSPARENT); ListViewScroller.createAndAttach(lv, this); lv.setFastScrollEnabled(true); lv.setTextFilterEnabled(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { lv.setOverscrollFooter(null); } lv.setVerticalFadingEdgeEnabled(false); lv.setFocusable(false); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { lv.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT); } lv.setDivider(new ColorDrawable(Color.LTGRAY)); lv.setDividerHeight(1); }
From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.subredditselect); // load personal list from saved prefereces, if null use default and save mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(SubredditSelectActivity.this); global = ((GlobalObjects) SubredditSelectActivity.this.getApplicationContext()); // get subreddit list and set adapter subredditList = global.getSubredditManager().getSubredditNames(); subsAdapter = new MySubredditsAdapter(this, subredditList); ListView subListView = (ListView) findViewById(R.id.sublist); subListView.setAdapter(subsAdapter); subListView.setTextFilterEnabled(true); subListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String subreddit = ((TextView) view.findViewById(R.id.subreddit_name)).getText().toString(); global.getSubredditManager().setFeedSubreddit(mAppWidgetId, subreddit); updateFeedAndFinish();/* w w w . j a va 2 s .co m*/ //System.out.println(sreddit+" selected"); } }); subsAdapter.sort(new Comparator<String>() { @Override public int compare(String s, String t1) { return s.compareToIgnoreCase(t1); } }); // get multi list and set adapter mMultiAdapter = new MyMultisAdapter(this); ListView multiListView = (ListView) findViewById(R.id.multilist); multiListView.setAdapter(mMultiAdapter); multiListView.setTextFilterEnabled(true); multiListView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == mMultiAdapter.getCount() - 1) { LinearLayout layout = (LinearLayout) getLayoutInflater().inflate(R.layout.dialog_multi_add, parent, false); final EditText name = (EditText) layout.findViewById(R.id.new_multi_name); AlertDialog.Builder builder = new AlertDialog.Builder(SubredditSelectActivity.this); builder.setTitle("Create A Multi").setView(layout) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); } }).setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { if (name.getText().toString().equals("")) { Toast.makeText(SubredditSelectActivity.this, "Please enter a name for the multi", Toast.LENGTH_LONG).show(); return; } new SubscriptionEditTask(SubscriptionEditTask.ACTION_MULTI_CREATE) .execute(name.getText().toString()); dialogInterface.dismiss(); } }).show(); } else { JSONObject multiObj = mMultiAdapter.getItem(position); try { String name = multiObj.getString("display_name"); String path = multiObj.getString("path"); global.getSubredditManager().setFeed(mAppWidgetId, name, path, true); updateFeedAndFinish(); } catch (JSONException e) { e.printStackTrace(); Toast.makeText(SubredditSelectActivity.this, "Error setting multi.", Toast.LENGTH_LONG) .show(); } } } }); Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { mAppWidgetId = 0; // Id of 4 zeros indicates its the app view, not a widget, that is being updated } else { String action = getIntent().getAction(); widgetFirstTimeSetup = action != null && action.equals("android.appwidget.action.APPWIDGET_CONFIGURE"); } } else { mAppWidgetId = 0; } final ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new SimpleTabsAdapter(new String[] { "My Subreddits", "My Multis" }, new int[] { R.id.sublist, R.id.multilist }, SubredditSelectActivity.this, null)); LinearLayout tabsLayout = (LinearLayout) findViewById(R.id.tab_widget); tabs = new SimpleTabsWidget(SubredditSelectActivity.this, tabsLayout); tabs.setViewPager(pager); addButton = (Button) findViewById(R.id.addsrbutton); addButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Intent intent = new Intent(SubredditSelectActivity.this, ViewAllSubredditsActivity.class); startActivityForResult(intent, 1); } }); refreshButton = (Button) findViewById(R.id.refreshloginbutton); refreshButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { if (global.mRedditData.isLoggedIn()) { if (pager.getCurrentItem() == 1) { refreshMultireddits(); } else { refreshSubreddits(); } } else { global.mRedditData.initiateLogin(SubredditSelectActivity.this); } } }); // sort button sortBtn = (Button) findViewById(R.id.sortselect); String sortTxt = "Sort: " + mSharedPreferences.getString("sort-" + (mAppWidgetId == 0 ? "app" : mAppWidgetId), "hot"); sortBtn.setText(sortTxt); sortBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { showSortDialog(); } }); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); } // set theme colors setThemeColors(); GlobalObjects.doShowWelcomeDialog(SubredditSelectActivity.this); }
From source file:com.todotxt.todotxttouch.TodoTxtTouch.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); currentActivityPointer = this; setContentView(R.layout.main);//from w w w .j a v a2 s. c om m_app = (TodoApplication) getApplication(); m_app.m_prefs.registerOnSharedPreferenceChangeListener(this); this.taskBag = m_app.getTaskBag(); m_adapter = new TaskAdapter(this, R.layout.list_item, taskBag.getTasks(), getLayoutInflater()); // listen to the ACTION_LOGOUT intent, if heard display LoginScreen // and finish() current activity IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction(Constants.INTENT_ACTION_ARCHIVE); intentFilter.addAction(Constants.INTENT_SYNC_CONFLICT); intentFilter.addAction(Constants.INTENT_ACTION_LOGOUT); intentFilter.addAction(Constants.INTENT_UPDATE_UI); intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); m_broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equalsIgnoreCase(Constants.INTENT_ACTION_ARCHIVE)) { // archive // refresh screen to remove completed tasks // push to remote //archiveTasks(); } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_ACTION_LOGOUT)) { taskBag.clear(); m_app.broadcastWidgetUpdate(); // Intent i = new Intent(context, LoginScreen.class); // startActivity(i); // finish(); } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_UPDATE_UI)) { updateSyncUI(intent.getBooleanExtra("redrawList", false)); } else if (intent.getAction().equalsIgnoreCase(Constants.INTENT_SYNC_CONFLICT)) { handleSyncConflict(); } else if (intent.getAction().equalsIgnoreCase(ConnectivityManager.CONNECTIVITY_ACTION)) { handleConnectivityChange(context); } // Taskbag might have changed, update drawer adapter // to reflect new/removed contexts and projects updateNavigationDrawer(); } }; registerReceiver(m_broadcastReceiver, intentFilter); setListAdapter(this.m_adapter); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); // Setup Navigation drawer m_drawerList = (ListView) findViewById(R.id.left_drawer); m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // Set the adapter for the list view updateNavigationDrawer(); SwipeDismissList.OnDismissCallback callback = new SwipeDismissList.OnDismissCallback() { // Gets called whenever the user deletes an item. public SwipeDismissList.Undoable onDismiss(AbsListView listView, final int position) { m_swipeList.setEnabled(false); final Task task = m_adapter.getItem(position); m_adapter.remove(task); ArrayList<Task> tasks = new ArrayList<Task>(); tasks.add(task); final boolean wasComplete = task.isCompleted(); final String popupTitle = listView.getResources() .getString(wasComplete ? R.string.swipe_action_unComplete : R.string.swipe_action_complete); if (wasComplete) { undoCompleteTasks(tasks, false); } else { completeTasks(tasks, false); } // Return an Undoable implementing every method return new SwipeDismissList.Undoable() { // Method is called when user undoes this deletion public void undo() { // Reinsert item to list ArrayList<Task> tasks = new ArrayList<Task>(); tasks.add(task); if (wasComplete) { completeTasks(tasks, false); } else { undoCompleteTasks(tasks, false); } } @Override public String getTitle() { return popupTitle; } }; } }; m_swipeList = new SwipeDismissList(lv, callback, SwipeDismissList.UndoMode.SINGLE_UNDO); m_swipeList.setPopupYOffset(56); m_swipeList.setAutoHideDelay(250); m_swipeList.setSwipeLayout(R.id.swipe_view); m_pullToRefreshAttacher = PullToRefreshAttacher.get(this); DefaultHeaderTransformer ht = (DefaultHeaderTransformer) m_pullToRefreshAttacher.getHeaderTransformer(); ht.setPullText(getString(R.string.pull_to_refresh)); ht.setRefreshingText(getString(R.string.syncing)); m_pullToRefreshAttacher.addRefreshableView(lv, this); // Delegate OnTouch calls to both libraries that want to receive them // Don't forward swipes when swiping on the left lv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { // Don't listen to gestures on the left area of the list // to prevent interference with the DrawerLayout ViewConfiguration vc = ViewConfiguration.get(view.getContext()); int deadZoneX = vc.getScaledTouchSlop(); if (motionEvent.getX() < deadZoneX) { return false; } m_pullToRefreshAttacher.onTouch(view, motionEvent); // Only listen to item swipes if we are not scrolling the // listview if (!mListScrolling && m_swipeList.onTouch(view, motionEvent)) { return false; } return false; } }); // We must set the scrollListener after the onTouchListener, // otherwise it will not fire lv.setOnScrollListener(this); initializeTasks(false); // Show search results Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { m_app.m_search = intent.getStringExtra(SearchManager.QUERY); Log.v(TAG, "Searched for " + m_app.m_search); m_app.storeFilters(); setFilteredTasks(false); } }
From source file:com.coincollection.MainActivity.java
/** * Finishes setting up the view once the database has been opened. */// w ww . j a va2s. co m private void finishViewSetup() { // Called from the InitTask after the database has been successfully // opened for the first time. Now we can be fairly sure that future // open's won't trigger an ANR issue. if (BuildConfig.DEBUG) { Log.v("mainActivity", "finishViewSetup"); } // Instantiate the DatabaseAdapter mDbAdapter = new DatabaseAdapter(this); // Populate mCollectionListEntries with the data from the database updateCollectionListFromDatabase(); // Instantiate the FrontAdapter mListAdapter = new FrontAdapter(mContext, mCollectionListEntries, mNumberOfCollections); ListView lv = (ListView) findViewById(R.id.main_activity_listview); lv.setAdapter(mListAdapter); // TODO Not sure what this does? lv.setTextFilterEnabled(true); // Typing narrows down the list // For when we use fragments, listen to the backstack so we can transition back here from // the fragment getSupportFragmentManager().addOnBackStackChangedListener(new FragmentManager.OnBackStackChangedListener() { public void onBackStackChanged() { if (0 == getSupportFragmentManager().getBackStackEntryCount()) { // We are back at this activity, so restore the ActionBar getSupportActionBar().setTitle(mRes.getString(R.string.app_name)); getSupportActionBar().setDisplayHomeAsUpEnabled(false); getSupportActionBar().setHomeButtonEnabled(false); // The collections may have been re-ordered, so update them here. updateCollectionListFromDatabase(); // Change it out with the new list mListAdapter.items = mCollectionListEntries; mListAdapter.numberOfCollections = mNumberOfCollections; mListAdapter.notifyDataSetChanged(); } } }); // Now set the onItemClickListener to perform a certain action based on what's clicked lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // See whether it was one of the special list entries (Add collection, delete // collection, etc.) if (position >= mNumberOfCollections) { int newPosition = position - mNumberOfCollections; Intent intent; switch (newPosition) { case ADD_COLLECTION: intent = new Intent(mContext, CoinPageCreator.class); startActivity(intent); break; case REMOVE_COLLECTION: if (mNumberOfCollections == 0) { Toast.makeText(mContext, mRes.getString(R.string.no_collections), Toast.LENGTH_SHORT) .show(); break; } // Thanks! // http://stackoverflow.com/questions/2397106/listview-in-alertdialog CharSequence[] names = new CharSequence[mNumberOfCollections]; for (int i = 0; i < mNumberOfCollections; i++) { names[i] = mCollectionListEntries.get(i).getName(); } AlertDialog.Builder delete_builder = new AlertDialog.Builder(mContext); delete_builder.setTitle(mRes.getString(R.string.select_collection_delete)); delete_builder.setItems(names, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { showDeleteConfirmation(mCollectionListEntries.get(item).getName()); } }); AlertDialog alert = delete_builder.create(); alert.show(); break; case IMPORT_COLLECTIONS: handleImportCollectionsPart1(); break; case EXPORT_COLLECTIONS: handleExportCollectionsPart1(); break; case REORDER_COLLECTIONS: if (mNumberOfCollections == 0) { Toast.makeText(mContext, mRes.getString(R.string.no_collections), Toast.LENGTH_SHORT) .show(); break; } // Get a list that excludes the spacers List<CollectionListInfo> tmp = mCollectionListEntries.subList(0, mNumberOfCollections); ArrayList<CollectionListInfo> collections = new ArrayList<>(tmp); ReorderCollections fragment = new ReorderCollections(); fragment.setCollectionList(collections); // Show the fragment used for reordering collections getSupportFragmentManager().beginTransaction() .add(R.id.main_activity_frame, fragment, "ReorderFragment").addToBackStack(null) .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit(); // Setup the actionbar for the reorder page // TODO Check for NULL getSupportActionBar().setTitle(mRes.getString(R.string.reorder_collection)); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); break; case ABOUT: LayoutInflater inflater = (LayoutInflater) mContext .getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.info_popup, (ViewGroup) findViewById(R.id.info_layout_root)); AlertDialog.Builder info_builder = new AlertDialog.Builder(mContext); info_builder.setView(layout); TextView tv = (TextView) layout.findViewById(R.id.info_textview); tv.setText(buildInfoText()); AlertDialog alertDialog = info_builder.create(); alertDialog.show(); break; } return; } // If it gets here, the user has selected a collection Intent intent = new Intent(mContext, CollectionPage.class); CollectionListInfo listEntry = mCollectionListEntries.get(position); intent.putExtra(CollectionPage.COLLECTION_NAME, listEntry.getName()); intent.putExtra(CollectionPage.COLLECTION_TYPE_INDEX, listEntry.getCollectionTypeIndex()); startActivity(intent); } }); }
From source file:nl.mpcjanssen.simpletask.Simpletask.java
private void handleIntent() { if (!m_app.isAuthenticated()) { Log.v(TAG, "handleIntent: not authenticated"); startLogin();/* w w w . j a va 2s . c o m*/ return; } if (!m_app.initialSyncDone()) { m_sync_dialog = new ProgressDialog(this, m_app.getActiveTheme()); m_sync_dialog.setIndeterminate(true); m_sync_dialog.setMessage("Initial Dropbox sync in progress, please wait...."); m_sync_dialog.setCancelable(false); m_sync_dialog.show(); } else if (m_sync_dialog != null) { m_sync_dialog.cancel(); } mFilter = new ActiveFilter(); m_leftDrawerList = (ListView) findViewById(R.id.left_drawer); m_rightDrawerList = (ListView) findViewById(R.id.right_drawer_list); m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); // Set the list's click listener m_leftDrawerList.setOnItemClickListener(new DrawerItemClickListener()); if (m_drawerLayout != null) { m_drawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ m_drawerLayout, /* DrawerLayout object */ R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */ R.string.changelist, /* "open drawer" description */ R.string.app_label /* "close drawer" description */ ) { /** * Called when a drawer has settled in a completely closed * state. */ public void onDrawerClosed(View view) { // setTitle(R.string.app_label); } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { // setTitle(R.string.changelist); } }; // Set the drawer toggle as the DrawerListener m_drawerLayout.setDrawerListener(m_drawerToggle); ActionBar actionBar = getActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setHomeButtonEnabled(true); } m_drawerToggle.syncState(); } // Show search or filter results Intent intent = getIntent(); if (Constants.INTENT_START_FILTER.equals(intent.getAction())) { mFilter.initFromIntent(intent); Log.v(TAG, "handleIntent: launched with filter" + mFilter); Log.v(TAG, "handleIntent: saving filter in prefs"); mFilter.saveInPrefs(TodoApplication.getPrefs()); } else { // Set previous filters and sort Log.v(TAG, "handleIntent: from m_prefs state"); mFilter.initFromPrefs(TodoApplication.getPrefs()); } // Initialize Adapter if (m_adapter == null) { m_adapter = new TaskAdapter(getLayoutInflater()); } m_adapter.setFilteredTasks(); getListView().setAdapter(this.m_adapter); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); lv.setMultiChoiceModeListener(new ActionBarListener()); lv.setClickable(true); lv.setOnItemClickListener(this); // If we were started with a selected task, // select it now and clear it from the intent String selectedTask = intent.getStringExtra(Constants.INTENT_SELECTED_TASK); if (!Strings.isEmptyOrNull(selectedTask)) { String[] parts = selectedTask.split(":", 2); setSelectedTask(Integer.valueOf(parts[0]), parts[1]); intent.removeExtra(Constants.INTENT_SELECTED_TASK); setIntent(intent); } else { // Set the adapter for the list view updateDrawers(); } if (m_savedInstanceState != null) { ArrayList<String> selection = m_savedInstanceState.getStringArrayList("selection"); int position = m_savedInstanceState.getInt("position"); if (selection != null) { for (String selected : selection) { String[] parts = selected.split(":", 2); setSelectedTask(Integer.valueOf(parts[0]), parts[1]); } } lv.setSelectionFromTop(position, 0); } }
From source file:terse.a1.TerseActivity.java
private void viewPath9display(String path, LayoutParams widgetParams) { String explain;//from w w w .j a va 2s .com if (terp_error != null) { explain = "terp_error = " + terp_error; } else { try { terp.say("Sending to terp: %s", path); final Dict d = terp.handleUrl(path, taQuery); explain = "DEFAULT EXPLANATION:\n\n" + d.toString(); Str TYPE = d.cls.terp.newStr("type"); Str VALUE = d.cls.terp.newStr("value"); Str TITLE = d.cls.terp.newStr("title"); Str type = (Str) d.dict.get(TYPE); Ur value = d.dict.get(VALUE); Ur title = d.dict.get(TITLE); // { // double ticks = Static.floatAt(d, "ticks", -1); // double nanos = Static.floatAt(d, "nanos", -1); // Toast.makeText( // getApplicationContext(), // Static.fmt("%d ticks, %.3f secs", (long) ticks, // (double) nanos / 1e9), Toast.LENGTH_SHORT) // .show(); // } if (type.str.equals("list") && value instanceof Vec) { final ArrayList<Ur> v = ((Vec) value).vec; final ArrayList<String> labels = new ArrayList<String>(); final ArrayList<String> links = new ArrayList<String>(); for (int i = 0; i < v.size(); i++) { Ur item = v.get(i); String label = item instanceof Str ? ((Str) item).str : item.toString(); if (item instanceof Vec && ((Vec) item).vec.size() == 2) { // OLD STYLE label = ((Vec) item).vec.get(0).toString(); Matcher m = LINK_P.matcher(label); if (m.lookingAt()) { label = m.group(2) + " " + m.group(3); } label += " [" + ((Vec) item).vec.get(1).toString().length() + "]"; links.add(null); // Use old style, not links. } else { // NEW STYLE label = item.toString(); if (label.charAt(0) == '/') { String link = Terp.WHITE_PLUS.split(label, 2)[0]; links.add(link); } else { links.add(""); } } labels.add(label); } if (labels.size() != links.size()) terp.toss("lables#%d links#%d", labels.size(), links.size()); ListView listv = new ListView(this); listv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, labels)); listv.setLayoutParams(widgetParams); listv.setTextFilterEnabled(true); listv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // When clicked, show a toast with the TextView text // Toast.makeText(getApplicationContext(), // ((TextView) view).getText(), // Toast.LENGTH_SHORT).show(); String toast_text = ((TextView) view).getText().toString(); // if (v.get(position) instanceof Vec) { if (links.get(position) == null) { // OLD STYLE Vec pair = (Vec) v.get(position); if (pair.vec.size() == 2) { if (pair.vec.get(0) instanceof Str) { String[] words = ((Str) pair.vec.get(0)).str.split("\\|"); Log.i("TT-WORDS", terp.arrayToString(words)); toast_text += "\n\n" + Static.arrayToString(words); if (words[1].equals("link")) { Uri uri = new Uri.Builder().scheme("terse").path(words[2]).build(); Intent intent = new Intent("android.intent.action.MAIN", uri); intent.setClass(getApplicationContext(), TerseActivity.class); startActivity(intent); } } } } else { // NEW STYLE terp.say("NEW STYLE LIST SELECT #%d link=<%s> label=<%s>", position, links.get(position), labels.get(position)); if (links.get(position).length() > 0) { Uri uri = new Uri.Builder().scheme("terse").path(links.get(position)).build(); Intent intent = new Intent("android.intent.action.MAIN", uri); intent.setClass(getApplicationContext(), TerseActivity.class); startActivity(intent); } } // } // Toast.makeText(getApplicationContext(), // ((TextView) view).getText(), // Toast.LENGTH_SHORT).show(); } }); setContentView(listv); return; } else if (type.str.equals("edit") && value instanceof Str) { final EditText ed = new EditText(this); ed.setText(taSaveMe == null ? value.toString() : taSaveMe); ed.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_VARIATION_LONG_MESSAGE | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); ed.setLayoutParams(widgetParams); // ed.setTextSize(TypedValue.COMPLEX_UNIT_SP, 22); ed.setTextAppearance(this, R.style.teletype); ed.setBackgroundColor(Color.BLACK); ed.setGravity(Gravity.TOP); ed.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_INSET); ed.setVerticalFadingEdgeEnabled(true); ed.setVerticalScrollBarEnabled(true); ed.setOnKeyListener(new OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { // If the event is a key-down event on the "enter" // button // if ((event.getAction() == KeyEvent.ACTION_DOWN) // && // (keyCode == KeyEvent.KEYCODE_ENTER)) { // // Perform action on key press // Toast.makeText(TerseActivity.this, ed.getText(), // Toast.LENGTH_SHORT).show(); // return true; // } return false; } }); Button btn = new Button(this); btn.setText("Save"); btn.setOnClickListener(new OnClickListener() { public void onClick(View v) { // Perform action on clicks String text = ed.getText().toString(); text = Parser.charSubsts(text); Toast.makeText(TerseActivity.this, text, Toast.LENGTH_SHORT).show(); String action = stringAt(d, "action"); String query = ""; String f1 = stringAt(d, "field1"); String v1 = stringAt(d, "value1"); String f2 = stringAt(d, "field2"); String v2 = stringAt(d, "value2"); f1 = (f1 == null) ? "f1null" : f1; v1 = (v1 == null) ? "v1null" : v1; f2 = (f2 == null) ? "f2null" : f2; v2 = (v2 == null) ? "v2null" : v2; startTerseActivity(action, query, stringAt(d, "field1"), stringAt(d, "value1"), stringAt(d, "field2"), stringAt(d, "value2"), "text", text); } }); LinearLayout linear = new LinearLayout(this); linear.setOrientation(LinearLayout.VERTICAL); linear.addView(btn); linear.addView(ed); setContentView(linear); return; } else if (type.str.equals("draw") && value instanceof Vec) { Vec v = ((Vec) value); DrawView dv = new DrawView(this, v.vec, d); dv.setLayoutParams(widgetParams); setContentView(dv); return; } else if (type.str.equals("live")) { Blk blk = value.mustBlk(); Blk event = Static.urAt(d, "event").asBlk(); TerseSurfView tsv = new TerseSurfView(this, blk, event); setContentView(tsv); return; } else if (type.str.equals("fnord")) { Blk blk = value.mustBlk(); Blk event = Static.urAt(d, "event").asBlk(); FnordView fnord = new FnordView(this, blk, event); setContentView(fnord); return; } else if (type.str.equals("world") && value instanceof Str) { String newWorld = value.toString(); if (Terp.WORLD_P.matcher(newWorld).matches()) { world = newWorld; resetTerp(); explain = Static.fmt("Switching to world <%s>\nUse menu to go Home.", world); Toast.makeText(getApplicationContext(), explain, Toast.LENGTH_LONG).show(); } else { terp.toss("Bad world syntax (must be 3 letters then 0 to 3 digits: <%s>", newWorld); } // Fall thru for explainv.setText(explain). } else if (type.str.equals("text")) { explain = "<<< " + title + " >>>\n\n" + value.toString(); // Fall thru for explainv.setText(explain). } else if (type.str.equals("html")) { final WebView webview = new WebView(this); // webview.loadData(value.toString(), "text/html", null); webview.loadDataWithBaseURL("terse://terse", value.toString(), "text/html", "UTF-8", null); webview.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // terp.say("WebView UrlLoading: url=%s", url); URI uri = URI.create("" + url); // terp.say("WebView UrlLoading: URI=%s", uri); terp.say("WebView UrlLoading: getPath=%s", uri.getPath()); terp.say("WebView UrlLoading: getQuery=%s", uri.getQuery()); // Toast.makeText(getApplicationContext(), // uri.toASCIIString(), Toast.LENGTH_SHORT) // .show(); // webview.invalidate(); // // TextView quick = new // TextView(TerseActivity.this); // quick.setText(uri.toASCIIString()); // quick.setBackgroundColor(Color.BLACK); // quick.setTextColor(Color.WHITE); // setContentView(quick); startTerseActivity(uri.getPath(), uri.getQuery()); return true; } }); // webview.setWebChromeClient(new WebChromeClient()); webview.getSettings().setBuiltInZoomControls(true); // webview.getSettings().setJavaScriptEnabled(true); webview.getSettings().setDefaultFontSize(18); webview.getSettings().setNeedInitialFocus(true); webview.getSettings().setSupportZoom(true); webview.getSettings().setSaveFormData(true); setContentView(webview); // ScrollView scrollv = new ScrollView(this); // scrollv.addView(webview); // setContentView(scrollv); return; } else { explain = "Unknown page type: " + type.str + " with vaule type: " + value.cls + "\n\n##############\n\n"; explain += value.toString(); // Fall thru for explainv.setText(explain). } } catch (Exception ex) { ex.printStackTrace(); explain = Static.describe(ex); } } TextView explainv = new TextView(this); explainv.setText(explain); explainv.setBackgroundColor(Color.BLACK); explainv.setTextSize(TypedValue.COMPLEX_UNIT_SP, 24); explainv.setTextColor(Color.YELLOW); SetContentViewWithHomeButtonAndScroll(explainv); }