List of usage examples for android.widget ListView ListView
public ListView(Context context)
From source file:androidVNC.VncCanvasActivity.java
private void selectColorModel() { // Stop repainting the desktop // because the display is composited! vncCanvas.disableRepaints();/*from ww w.j a v a 2s . c o m*/ String[] choices = new String[COLORMODEL.values().length]; int currentSelection = -1; for (int i = 0; i < choices.length; i++) { COLORMODEL cm = COLORMODEL.values()[i]; choices[i] = cm.toString(); if (vncCanvas.isColorModel(cm)) currentSelection = i; } final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); ListView list = new ListView(this); list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, choices)); list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); list.setItemChecked(currentSelection, true); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { dialog.dismiss(); COLORMODEL cm = COLORMODEL.values()[arg2]; vncCanvas.setColorModel(cm); connection.setColorModel(cm.nameString()); connection.save(database.getWritableDatabase()); //Toast.makeText(VncCanvasActivity.this,"Updating Color Model to " + cm.toString(), Toast.LENGTH_SHORT).show(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { Log.i(TAG, "Color Model Selector dismissed"); // Restore desktop repaints vncCanvas.enableRepaints(); } }); dialog.setContentView(list); dialog.show(); }
From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java
/** * Shows a list of primary user apps in a dialog. * * @param dialogTitle the title to show for the dialog * @param callback will be called with the list apps that the user has selected when he closes * the dialog. The callback is not fired if the user cancels. *///w w w. ja v a 2s. com private void showManageLockTaskListPrompt(int dialogTitle, final ManageLockTaskListCallback callback) { if (getActivity() == null || getActivity().isFinishing()) { return; } Intent launcherIntent = new Intent(Intent.ACTION_MAIN); launcherIntent.addCategory(Intent.CATEGORY_LAUNCHER); final List<ResolveInfo> primaryUserAppList = mPackageManager.queryIntentActivities(launcherIntent, 0); if (primaryUserAppList.isEmpty()) { showToast(R.string.no_primary_app_available); } else { Collections.sort(primaryUserAppList, new ResolveInfo.DisplayNameComparator(mPackageManager)); final LockTaskAppInfoArrayAdapter appInfoArrayAdapter = new LockTaskAppInfoArrayAdapter(getActivity(), R.id.pkg_name, primaryUserAppList); ListView listView = new ListView(getActivity()); listView.setAdapter(appInfoArrayAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { appInfoArrayAdapter.onItemClick(parent, view, position, id); } }); new AlertDialog.Builder(getActivity()).setTitle(getString(dialogTitle)).setView(listView) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String[] lockTaskEnabledArray = appInfoArrayAdapter.getLockTaskList(); callback.onPositiveButtonClicked(lockTaskEnabledArray); } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }).show(); } }
From source file:com.hichinaschool.flashcards.anki.CardEditor.java
private StyledDialog createDialogIntentInformation(Builder builder, Resources res) { builder.setTitle(res.getString(R.string.intent_add_saved_information)); ListView listView = new ListView(this); mIntentInformationAdapter = new SimpleAdapter(this, mIntentInformation, R.layout.card_item, new String[] { "source", "target", "id" }, new int[] { R.id.card_sfld, R.id.card_tmpl, R.id.card_item }); listView.setAdapter(mIntentInformationAdapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override// ww w . ja v a 2 s . com public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent intent = new Intent(CardEditor.this, CardEditor.class); intent.putExtra(EXTRA_CALLER, CALLER_CARDEDITOR_INTENT_ADD); HashMap<String, String> map = mIntentInformation.get(position); intent.putExtra(EXTRA_CONTENTS, map.get("fields")); intent.putExtra(EXTRA_ID, map.get("id")); startActivityForResult(intent, REQUEST_INTENT_ADD); if (AnkiDroidApp.SDK_VERSION > 4) { ActivityTransitionAnimation.slide(CardEditor.this, ActivityTransitionAnimation.FADE); } mIntentInformationDialog.dismiss(); } }); mCardItemBackground = Themes.getCardBrowserBackground()[0]; mIntentInformationAdapter.setViewBinder(new SimpleAdapter.ViewBinder() { @Override public boolean setViewValue(View view, Object arg1, String text) { if (view.getId() == R.id.card_item) { view.setBackgroundResource(mCardItemBackground); return true; } return false; } }); listView.setBackgroundColor(android.R.attr.colorBackground); listView.setDrawSelectorOnTop(true); listView.setFastScrollEnabled(true); Themes.setContentStyle(listView, Themes.CALLER_CARDEDITOR_INTENTDIALOG); builder.setView(listView, false, true); builder.setCancelable(true); builder.setPositiveButton(res.getString(R.string.intent_add_clear_all), new OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { MetaDB.resetIntentInformation(CardEditor.this); mIntentInformation.clear(); dialog.dismiss(); } }); StyledDialog dialog = builder.create(); mIntentInformationDialog = dialog; return dialog; }
From source file:com.iiordanov.bVNC.RemoteCanvasActivity.java
private void selectColorModel() { String[] choices = new String[COLORMODEL.values().length]; int currentSelection = -1; for (int i = 0; i < choices.length; i++) { COLORMODEL cm = COLORMODEL.values()[i]; choices[i] = cm.toString();/*from w w w .jav a2s .c o m*/ if (canvas.isColorModel(cm)) currentSelection = i; } final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); ListView list = new ListView(this); list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, choices)); list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); list.setItemChecked(currentSelection, true); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { dialog.dismiss(); COLORMODEL cm = COLORMODEL.values()[arg2]; canvas.setColorModel(cm); connection.setColorModel(cm.nameString()); connection.save(database.getWritableDatabase()); database.close(); Toast.makeText(RemoteCanvasActivity.this, getString(R.string.info_update_color_model_to) + cm.toString(), Toast.LENGTH_SHORT).show(); } }); dialog.setContentView(list); dialog.show(); }
From source file:com.mods.grx.settings.GrxSettingsActivity.java
/******************** RESTORE ****************************************************/ private void show_restore_dialog() { ListView lv = new ListView(this); File ficheros = new File(Common.BackupsDir + File.separator); FileFilter ff = new FileFilter() { @Override//from w ww . j av a2 s.c o m public boolean accept(File pathname) { String ruta; if (pathname.isFile()) { ruta = pathname.getAbsolutePath().toLowerCase(); if (ruta.contains("." + getString(R.string.gs_backup_ext))) { return true; } } return false; } }; File fa[] = ficheros.listFiles(ff); if (fa.length == 0) show_snack_message(getString(R.string.gs_no_backups)); else { AdapterBackups ab = new AdapterBackups(); ab.AdapterBackups(this, fa); ListView lista = new ListView(this); lista.setAdapter(ab); lista.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { TextView tv = (TextView) view.findViewById(android.R.id.text1); String file_name = tv.getText().toString(); mRestoreDialog.dismiss(); mRestoreDialog = null; File f = new File(Common.BackupsDir + File.separator + file_name + "." + getString(R.string.gs_backup_ext)); if (f.exists()) show_restore_confirmation_dialog(file_name); else show_snack_message(getString(R.string.gs_err_desconocido_restaurar)); } }); AlertDialog.Builder abd = new AlertDialog.Builder(this); abd.setTitle(R.string.gs_tit_restaurar); abd.setMessage(R.string.gs_mensaje_restaurar); abd.setView(lista); mRestoreDialog = abd.create(); mRestoreDialog.show(); } }
From source file:cm.aptoide.pt.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { AptoideThemePicker.setAptoideTheme(this); super.onCreate(savedInstanceState); serviceDownloadManagerIntent = new Intent(this, ServiceDownloadManager.class); startService(serviceDownloadManagerIntent); mContext = this; File sdcard_file = new File(SDCARD); if (!sdcard_file.exists() || !sdcard_file.canWrite()) { View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null); Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView); final AlertDialog noSDDialog = dialogBuilder.create(); noSDDialog.setTitle(getText(R.string.remote_in_noSD_title)); noSDDialog.setIcon(android.R.drawable.ic_dialog_alert); TextView message = (TextView) simpleView.findViewById(R.id.dialog_message); message.setText(getText(R.string.remote_in_noSD)); noSDDialog.setCancelable(false); noSDDialog.setButton(Dialog.BUTTON_NEUTRAL, getString(android.R.string.ok), new Dialog.OnClickListener() { @Override//www.j a va 2 s . c om public void onClick(DialogInterface arg0, int arg1) { finish(); } }); noSDDialog.show(); } else { StatFs stat = new StatFs(sdcard_file.getPath()); long blockSize = stat.getBlockSize(); long totalBlocks = stat.getBlockCount(); long availableBlocks = stat.getAvailableBlocks(); long total = (blockSize * totalBlocks) / 1024 / 1024; long avail = (blockSize * availableBlocks) / 1024 / 1024; Log.d("Aptoide", "* * * * * * * * * *"); Log.d("Aptoide", "Total: " + total + " Mb"); Log.d("Aptoide", "Available: " + avail + " Mb"); if (avail < 10) { Log.d("Aptoide", "No space left on SDCARD..."); Log.d("Aptoide", "* * * * * * * * * *"); View simpleView = LayoutInflater.from(this).inflate(R.layout.dialog_simple_layout, null); Builder dialogBuilder = new AlertDialog.Builder(this).setView(simpleView); final AlertDialog noSpaceDialog = dialogBuilder.create(); noSpaceDialog.setIcon(android.R.drawable.ic_dialog_alert); TextView message = (TextView) simpleView.findViewById(R.id.dialog_message); message.setText(getText(R.string.remote_in_noSDspace)); noSpaceDialog.setButton(Dialog.BUTTON_NEUTRAL, getText(android.R.string.ok), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { finish(); } }); noSpaceDialog.show(); } else { SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(mContext); editor = PreferenceManager.getDefaultSharedPreferences(mContext).edit(); if (!sPref.contains("matureChkBox")) { editor.putBoolean("matureChkBox", ApplicationAptoide.MATURECONTENTSWITCHVALUE); SharedPreferences sPrefOld = getSharedPreferences("aptoide_prefs", MODE_PRIVATE); if (sPrefOld.getString("app_rating", "none").equals("Mature")) { editor.putBoolean("matureChkBox", false); } } if (!sPref.contains("version")) { ApplicationAptoide.setRestartLauncher(true); try { editor.putInt("version", getPackageManager().getPackageInfo(getPackageName(), 0).versionCode); } catch (NameNotFoundException e) { e.printStackTrace(); } } if (sPref.getString("myId", null) == null) { String rand_id = UUID.randomUUID().toString(); editor.putString("myId", rand_id); } if (sPref.getInt("scW", 0) == 0 || sPref.getInt("scH", 0) == 0) { DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); editor.putInt("scW", dm.widthPixels); editor.putInt("scH", dm.heightPixels); } editor.commit(); File file = new File(LOCAL_PATH + "/apks"); if (!file.exists()) { file.mkdirs(); } new Thread(new Runnable() { @Override public void run() { // Note the L that tells the compiler to interpret the // number as a Long final long MAXFILEAGE = 2678400000L; // 1 month in // milliseconds // Get file handle to the directory. In this case the // application files dir File dir = new File(LOCAL_PATH + "/apks"); // Optain list of files in the directory. // listFiles() returns a list of File objects to each // file found. File[] files = dir.listFiles(); // Loop through all files for (File f : files) { // Get the last modified date. Miliseconds since // 1970 long lastmodified = f.lastModified(); // Do stuff here to deal with the file.. // For instance delete files older than 1 month if (lastmodified + MAXFILEAGE < System.currentTimeMillis()) { f.delete(); } } } }).start(); db = Database.getInstance(); Intent i = new Intent(mContext, MainService.class); startService(i); bindService(i, conn, Context.BIND_AUTO_CREATE); order = Order.values()[PreferenceManager.getDefaultSharedPreferences(mContext).getInt("order_list", 0)]; registerReceiver(updatesReceiver, new IntentFilter("update")); registerReceiver(statusReceiver, new IntentFilter("status")); registerReceiver(loginReceiver, new IntentFilter("login")); registerReceiver(storePasswordReceiver, new IntentFilter("401")); registerReceiver(redrawInstalledReceiver, new IntentFilter("pt.caixamagica.aptoide.REDRAW")); if (!ApplicationAptoide.MULTIPLESTORES) { registerReceiver(parseFailedReceiver, new IntentFilter("PARSE_FAILED")); } registerReceiver(newRepoReceiver, new IntentFilter("pt.caixamagica.aptoide.NEWREPO")); registered = true; categoriesStrings = new HashMap<String, Integer>(); // categoriesStrings.put("Applications", R.string.applications); boolean serversFileIsEmpty = true; if (sPref.getBoolean("firstrun", true)) { // Intent shortcutIntent = new Intent(Intent.ACTION_MAIN); // shortcutIntent.setClassName("cm.aptoide.pt", // "cm.aptoide.pt.Start"); // final Intent intent = new Intent(); // intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, // shortcutIntent); // // intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, // getString(R.string.app_name)); // Parcelable iconResource = // Intent.ShortcutIconResource.fromContext(this, // R.drawable.ic_launcher); // // intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, // iconResource); // intent.putExtra("duplicate", false); // intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); // sendBroadcast(intent); if (new File(LOCAL_PATH + "/servers.xml").exists() && ApplicationAptoide.DEFAULTSTORENAME == null) { try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); MyappHandler handler = new MyappHandler(); sp.parse(new File(LOCAL_PATH + "/servers.xml"), handler); ArrayList<String> server = handler.getServers(); if (server.isEmpty()) { serversFileIsEmpty = true; } else { getIntent().putExtra("newrepo", server); } } catch (Exception e) { e.printStackTrace(); } } editor.putBoolean("firstrun", false); editor.putBoolean("orderByCategory", true); editor.commit(); } if (getIntent().hasExtra("newrepo")) { ArrayList<String> repos = (ArrayList<String>) getIntent().getSerializableExtra("newrepo"); for (final String uri2 : repos) { View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null); Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView); final AlertDialog addNewRepoDialog = dialogBuilder.create(); addNewRepoDialog.setTitle(getString(R.string.add_store)); addNewRepoDialog.setIcon(android.R.drawable.ic_menu_add); TextView message = (TextView) simpleView.findViewById(R.id.dialog_message); message.setText((getString(R.string.newrepo_alrt) + uri2 + " ?")); addNewRepoDialog.setCancelable(false); addNewRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { dialogAddStore(uri2, null, null); } }); addNewRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }); addNewRepoDialog.show(); } } else if (db.getStores(false).getCount() == 0 && ApplicationAptoide.DEFAULTSTORENAME == null && serversFileIsEmpty) { View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null); Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView); final AlertDialog addAppsRepoDialog = dialogBuilder.create(); addAppsRepoDialog.setTitle(getString(R.string.add_store)); addAppsRepoDialog.setIcon(android.R.drawable.ic_menu_add); TextView message = (TextView) simpleView.findViewById(R.id.dialog_message); message.setText(getString(R.string.myrepo_alrt) + "\n" + "http://apps.store.aptoide.com/"); addAppsRepoDialog.setCancelable(false); addAppsRepoDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { dialogAddStore("http://apps.store.aptoide.com", null, null); } }); addAppsRepoDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.cancel(); } }); addAppsRepoDialog.show(); } new Thread(new Runnable() { @Override public void run() { try { getUpdateParameters(); if (getPackageManager().getPackageInfo(getPackageName(), 0).versionCode < Integer .parseInt(updateParams.get("versionCode"))) { runOnUiThread(new Runnable() { @Override public void run() { requestUpdateSelf(); } }); } } catch (Exception e) { e.printStackTrace(); } } }).start(); } featuredView = LayoutInflater.from(mContext).inflate(R.layout.page_featured, null); availableView = LayoutInflater.from(mContext).inflate(R.layout.page_available, null); updateView = LayoutInflater.from(mContext).inflate(R.layout.page_updates, null); banner = (LinearLayout) availableView.findViewById(R.id.banner); breadcrumbs = (LinearLayout) LayoutInflater.from(mContext).inflate(R.layout.breadcrumb_container, null); installedView = new ListView(mContext); updatesListView = (ListView) updateView.findViewById(R.id.updates_list); availableListView = (ListView) availableView.findViewById(R.id.available_list); joinStores = (CheckBox) availableView.findViewById(R.id.join_stores); availableAdapter = new AvailableListAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); installedAdapter = new InstalledAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER, db); updatesAdapter = new UpdatesAdapter(mContext, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); pb = (TextView) availableView.findViewById(R.id.loading_pb); addStoreButton = availableView.findViewById(R.id.add_store); bannerStoreAvatar = (ImageView) banner.findViewById(R.id.banner_store_avatar); bannerStoreName = (TextView) banner.findViewById(R.id.banner_store_name); bannerStoreDescription = (AutoScaleTextView) banner.findViewById(R.id.banner_store_description); } }
From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java
/** * Displays an alert dialog that allows the user to select applications from all non-system * applications installed on the current profile. After the user selects an app, this app can't * be uninstallation./* www.ja v a 2s .c o m*/ */ private void showBlockUninstallationPrompt() { Activity activity = getActivity(); if (activity == null || activity.isFinishing()) { return; } List<ApplicationInfo> applicationInfoList = mPackageManager.getInstalledApplications(0 /* No flag */); List<ResolveInfo> resolveInfoList = new ArrayList<ResolveInfo>(); Collections.sort(applicationInfoList, new ApplicationInfo.DisplayNameComparator(mPackageManager)); for (ApplicationInfo applicationInfo : applicationInfoList) { // Ignore system apps because they can't be uninstalled. if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) { ResolveInfo resolveInfo = new ResolveInfo(); resolveInfo.resolvePackageName = applicationInfo.packageName; resolveInfoList.add(resolveInfo); } } final BlockUninstallationInfoArrayAdapter blockUninstallationInfoArrayAdapter = new BlockUninstallationInfoArrayAdapter( getActivity(), R.id.pkg_name, resolveInfoList); ListView listview = new ListView(getActivity()); listview.setAdapter(blockUninstallationInfoArrayAdapter); listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int pos, long id) { blockUninstallationInfoArrayAdapter.onItemClick(parent, view, pos, id); } }); new AlertDialog.Builder(getActivity()).setTitle(R.string.block_uninstallation_title).setView(listview) .setPositiveButton(R.string.close, null /* Nothing to do */).show(); }
From source file:com.linkbubble.ui.ContentView.java
private void onUrlLongClick(final WebView webView, final String urlAsString, final int type) { Resources resources = getResources(); final ArrayList<String> longClickSelections = new ArrayList<String>(); final String shareLabel = resources.getString(R.string.action_share); longClickSelections.add(shareLabel); String defaultBrowserLabel = Settings.get().getDefaultBrowserLabel(); final String leftConsumeBubbleLabel = Settings.get().getConsumeBubbleLabel(BubbleAction.ConsumeLeft); if (leftConsumeBubbleLabel != null) { if (defaultBrowserLabel == null || defaultBrowserLabel.equals(leftConsumeBubbleLabel) == false) { longClickSelections.add(leftConsumeBubbleLabel); }//w w w. j a v a 2 s . c om } final String rightConsumeBubbleLabel = Settings.get().getConsumeBubbleLabel(BubbleAction.ConsumeRight); if (rightConsumeBubbleLabel != null) { if (defaultBrowserLabel == null || defaultBrowserLabel.equals(rightConsumeBubbleLabel) == false) { longClickSelections.add(rightConsumeBubbleLabel); } } // Long pressing for a link doesn't work reliably, re #279 //final String copyLinkLabel = resources.getString(R.string.action_copy_to_clipboard); //longClickSelections.add(copyLinkLabel); Collections.sort(longClickSelections); final String openLinkInNewBubbleLabel = resources.getString(R.string.action_open_link_in_new_bubble); final String openImageInNewBubbleLabel = resources.getString(R.string.action_open_image_in_new_bubble); if (type == WebView.HitTestResult.IMAGE_TYPE || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { longClickSelections.add(0, openImageInNewBubbleLabel); } if (type == WebView.HitTestResult.SRC_ANCHOR_TYPE || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { longClickSelections.add(0, openLinkInNewBubbleLabel); } final String openInBrowserLabel = defaultBrowserLabel != null ? String.format(resources.getString(R.string.action_open_in_browser), defaultBrowserLabel) : null; if (openInBrowserLabel != null) { longClickSelections.add(1, openInBrowserLabel); } final String saveImageLabel = resources.getString(R.string.action_save_image); if (type == WebView.HitTestResult.IMAGE_TYPE || type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { longClickSelections.add(saveImageLabel); } ListView listView = new ListView(getContext()); listView.setAdapter(new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, longClickSelections.toArray(new String[0]))); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { CrashTracking.log("ContentView listView.setOnItemClickListener"); String string = longClickSelections.get(position); if (string.equals(openLinkInNewBubbleLabel) && type == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE) { Message msg = new Message(); msg.setTarget(new Handler() { @Override public void handleMessage(Message msg) { Bundle b = msg.getData(); if (b != null && b.getString("url") != null) { MainController.get().openUrl(b.getString("url"), System.currentTimeMillis(), false, Analytics.OPENED_URL_FROM_NEW_TAB); } } }); webView.requestFocusNodeHref(msg); } if (string.equals(openLinkInNewBubbleLabel) || string.equals(openImageInNewBubbleLabel)) { MainController controller = MainController.get(); if (null != controller) { controller.openUrl(urlAsString, System.currentTimeMillis(), false, Analytics.OPENED_URL_FROM_NEW_TAB); } else { MainApplication.openLink(getContext(), urlAsString, Analytics.OPENED_URL_FROM_NEW_TAB); } } else if (openInBrowserLabel != null && string.equals(openInBrowserLabel)) { openInBrowser(urlAsString); } else if (string.equals(shareLabel)) { showSelectShareMethod(urlAsString, false); } else if (string.equals(saveImageLabel)) { saveImage(urlAsString); } else if (leftConsumeBubbleLabel != null && string.equals(leftConsumeBubbleLabel)) { MainApplication.handleBubbleAction(getContext(), BubbleAction.ConsumeLeft, urlAsString, -1); } else if (rightConsumeBubbleLabel != null && string.equals(rightConsumeBubbleLabel)) { MainApplication.handleBubbleAction(getContext(), BubbleAction.ConsumeRight, urlAsString, -1); //} else if (string.equals(copyLinkLabel)) { // MainApplication.copyLinkToClipboard(getContext(), urlAsString, R.string.link_copied_to_clipboard); } if (mLongPressAlertDialog != null) { mLongPressAlertDialog.dismiss(); } } }); listView.setBackgroundColor(Settings.get().getThemedContentViewColor()); mLongPressAlertDialog = new AlertDialog.Builder(getContext()).create(); mLongPressAlertDialog.setView(listView); mLongPressAlertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); mLongPressAlertDialog.show(); }
From source file:com.nttec.everychan.ui.presentation.BoardFragment.java
private void showThreadPreviewDialog(final int position) { final List<PresentationItemModel> items = new ArrayList<>(); final int bgShadowResource = ThemeUtils.getThemeResId(activity.getTheme(), R.attr.dialogBackgroundShadow); final int bgColor = ThemeUtils.getThemeColor(activity.getTheme(), R.attr.activityRootBackground, Color.BLACK);/* ww w. j ava 2 s .co m*/ final View tmpV = new View(activity); final Dialog tmpDlg = new Dialog(activity); tmpDlg.getWindow().setBackgroundDrawableResource(bgShadowResource); tmpDlg.requestWindowFeature(Window.FEATURE_NO_TITLE); tmpDlg.setCanceledOnTouchOutside(true); tmpDlg.setContentView(tmpV); tmpDlg.show(); Runnable next = new Runnable() { @Override public void run() { final int dlgWidth = tmpV.getWidth(); tmpDlg.hide(); tmpDlg.cancel(); final Dialog dialog = new Dialog(activity); if (presentationModel.source != null && presentationModel.source.threads != null && presentationModel.source.threads.length > position && presentationModel.source.threads[position].posts != null && presentationModel.source.threads[position].posts.length > 0) { final String threadNumber = presentationModel.source.threads[position].posts[0].number; ClickableURLSpan.URLSpanClickListener spanClickListener = new ClickableURLSpan.URLSpanClickListener() { @Override public void onClick(View v, ClickableURLSpan span, String url, String referer) { if (url.startsWith("#")) { try { UrlPageModel threadPageModel = new UrlPageModel(); threadPageModel.chanName = chan.getChanName(); threadPageModel.type = UrlPageModel.TYPE_THREADPAGE; threadPageModel.boardName = tabModel.pageModel.boardName; threadPageModel.threadNumber = threadNumber; url = chan.buildUrl(threadPageModel) + url; dialog.dismiss(); UrlHandler.open(chan.fixRelativeUrl(url), activity); } catch (Exception e) { Logger.e(TAG, e); } } else { dialog.dismiss(); UrlHandler.open(chan.fixRelativeUrl(url), activity); } } }; AndroidDateFormat.initPattern(); String datePattern = AndroidDateFormat.getPattern(); DateFormat dateFormat = datePattern == null ? DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT) : new SimpleDateFormat(datePattern, Locale.US); dateFormat.setTimeZone(settings.isLocalTime() ? TimeZone.getDefault() : TimeZone.getTimeZone(presentationModel.source.boardModel.timeZoneId)); int postsCount = presentationModel.source.threads[position].postsCount; boolean showIndex = presentationModel.source.threads[position].posts.length <= postsCount; int curPostIndex = postsCount - presentationModel.source.threads[position].posts.length + 1; boolean openSpoilers = settings.openSpoilers(); for (int i = 0; i < presentationModel.source.threads[position].posts.length; ++i) { PresentationItemModel model = new PresentationItemModel( presentationModel.source.threads[position].posts[i], chan.getChanName(), presentationModel.source.pageModel.boardName, presentationModel.source.pageModel.threadNumber, dateFormat, spanClickListener, imageGetter, ThemeUtils.ThemeColors.getInstance(activity.getTheme()), openSpoilers, floatingModels, null); model.buildSpannedHeader(showIndex ? (i == 0 ? 1 : ++curPostIndex) : -1, presentationModel.source.boardModel.bumpLimit, presentationModel.source.boardModel.defaultUserName, null, false); items.add(model); } } else { items.add(presentationModel.presentationList.get(position)); } ListView dlgList = new ListView(activity); dlgList.setAdapter(new ArrayAdapter<PresentationItemModel>(activity, 0, items) { @Override public View getView(int position, View convertView, ViewGroup parent) { View view = adapter.getView(position, convertView, parent, dlgWidth, getItem(position)); view.setBackgroundColor(bgColor); return view; } }); dialog.getWindow().setBackgroundDrawableResource(bgShadowResource); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setCanceledOnTouchOutside(true); dialog.setContentView(dlgList); dialog.show(); dialogs.add(dialog); } }; if (tmpV.getWidth() != 0) { next.run(); } else { AppearanceUtils.callWhenLoaded(tmpDlg.getWindow().getDecorView(), next); } }