@Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Intent intent; if (position == 0) { intent = BookmarkListActivity.createIntent( getApplicationContext(), Db.Bookmark2.kind_bookmark, 0); } else if (position == 1) { intent = BookmarkListActivity.createIntent( getApplicationContext(), Db.Bookmark2.kind_note, 0); } else if (position == 2) { intent = BookmarkListActivity.createIntent( getApplicationContext(), Db.Bookmark2.kind_highlight, 0); } else if (position == 3) { intent = BookmarkListActivity.createIntent( getApplicationContext(), Db.Bookmark2.kind_bookmark, BookmarkListActivity.LABELID_noLabel); } else { Label label = adapter.getItem(position); if (label != null) { intent = BookmarkListActivity.createIntent( getApplicationContext(), Db.Bookmark2.kind_bookmark, label._id); } else { return; } } startActivityForResult(intent, REQCODE_bukmakList); }
public BookmarkFilterController(DragSortListView lv, BookmarkFilterAdapter adapter) { super(lv, R.id.drag_handle, DragSortController.ON_DOWN, 0); this.lv = lv; mDivPos = adapter.getDivPosition(); setRemoveEnabled(false); }
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQCODE_bukmakList) { if (resultCode == RESULT_OK) { int ari = data.getIntExtra(BookmarkActivity.EXTRA_ariTerpilih, 0); if (ari != 0) { // 0 berarti ga ada apa2, karena ga ada pasal 0 ayat 0 Intent res = new Intent(); res.putExtra(EXTRA_ariTerpilih, ari); setResult(RESULT_OK, res); finish(); } } } adapter.reload(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bookmark); setTitle(R.string.judul_bukmak_activity); adapter = new BookmarkFilterAdapter(); adapter.reload(); lv = V.get(this, android.R.id.list); lv.setDropListener(adapter); lv.setOnItemClickListener(lv_click); lv.setAdapter(adapter); BookmarkFilterController c = new BookmarkFilterController(lv, adapter); lv.setFloatViewManager(c); lv.setOnTouchListener(c); registerForContextMenu(lv); Intent intent = getIntent(); if (U.equals(intent.getAction(), Intent.ACTION_VIEW)) { Uri data = intent.getData(); if (data != null && (U.equals(data.getScheme(), "content") || U.equals(data.getScheme(), "file"))) { // $NON-NLS-1$ //$NON-NLS-2$ try { final InputStream inputStream = getContentResolver().openInputStream(data); final AlertDialog[] dialog = {null}; dialog[0] = new AlertDialog.Builder(BookmarkActivity.this) .setMessage(R.string.apakah_anda_mau_menumpuk_pembatas_buku_dan_catatan_tanya) .setNegativeButton(R.string.cancel, null) .setNeutralButton( R.string.no, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog_, int which) { dialog[0].setOnDismissListener(null); importBookmarks(inputStream, false, true); } }) .setPositiveButton( R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog_, int which) { dialog[0].setOnDismissListener(null); importBookmarks(inputStream, true, true); } }) .show(); dialog[0].setOnDismissListener(finishActivityListener); } catch (FileNotFoundException e) { msgbox(getString(R.string.bl_file_not_found_filename, data.toString())) .setOnDismissListener(finishActivityListener); } } } }
@Override public boolean onContextItemSelected(android.view.MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int itemId = item.getItemId(); if (itemId == R.id.menuRenameLabel) { final Label label = adapter.getItem(info.position); if (label == null) { return true; } LabelEditorDialog.show( this, label.title, getString(R.string.rename_label_title), new OkListener() { @Override public void onOk(String judul) { label.title = judul; S.getDb().updateLabel(label); adapter.notifyDataSetChanged(); } }); return true; } else if (itemId == R.id.menuDeleteLabel) { final Label label = adapter.getItem(info.position); if (label == null) { return true; } int nbukmak = S.getDb().countBukmakDenganLabel(label); if (nbukmak == 0) { // tiada, langsung hapus aja! S.getDb().hapusLabelById(label._id); adapter.reload(); } else { new AlertDialog.Builder(this) .setMessage( getString( R.string.are_you_sure_you_want_to_delete_the_label_label, label.title, nbukmak)) .setNegativeButton(R.string.cancel, null) .setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { S.getDb().hapusLabelById(label._id); adapter.reload(); } }) .show(); } return true; } else if (itemId == R.id.menuChangeLabelColor) { final Label label = adapter.getItem(info.position); if (label == null) { return true; } int warnaLatarRgb = U.decodeLabelBackgroundColor(label.backgroundColor); new AmbilWarnaDialog( BookmarkActivity.this, 0xff000000 | warnaLatarRgb, new OnAmbilWarnaListener() { @Override public void onOk(AmbilWarnaDialog dialog, int color) { if (color == -1) { label.backgroundColor = null; } else { label.backgroundColor = U.encodeLabelBackgroundColor(0x00ffffff & color); } S.getDb().updateLabel(label); adapter.notifyDataSetChanged(); } @Override public void onCancel(AmbilWarnaDialog dialog) { // nop } }) .show(); return true; } return false; }