List of usage examples for android.app AlertDialog setCancelable
public void setCancelable(boolean flag)
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Creates and shows a custom Alert dialog that will execute * the actions specified for positive, negative and * neutral buttons./* w w w. j a v a2 s. c om*/ * * @param context * @param title * @param message * @param positiveBtnActions Can be null. When null button is not shown. * @param negativeBtnActions Can be null. When null button is not shown. * @param neutralBtnActions Can be null. */ public static void dialog_showCustomActionsDialog(Context context, String title, String message, String positiveBtnText, final Runnable positiveBtnActions, String negativeBtnText, final Runnable negativeBtnActions, String neutralBtnText, final Runnable neutralBtnActions) { AlertDialog dialog = new AlertDialog.Builder(context).create(); dialog.setTitle(title); dialog.setMessage(message); dialog.setCancelable(true); dialog.setButton(AlertDialog.BUTTON_NEUTRAL, neutralBtnText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (neutralBtnActions != null) { neutralBtnActions.run(); } dialog.dismiss(); } }); if (negativeBtnActions != null) { dialog.setButton(AlertDialog.BUTTON_NEGATIVE, negativeBtnText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { negativeBtnActions.run(); } }); } if (positiveBtnActions != null) { dialog.setButton(AlertDialog.BUTTON_POSITIVE, positiveBtnText, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { positiveBtnActions.run(); } }); } dialog.show(); }
From source file:com.farmerbb.taskbar.MainActivity.java
private void proceedWithAppLaunch(Bundle savedInstanceState) { setContentView(R.layout.main);//from ww w .j a v a2s . c o m ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setCustomView(R.layout.switch_layout); actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM); } theSwitch = (SwitchCompat) findViewById(R.id.the_switch); if (theSwitch != null) { final SharedPreferences pref = U.getSharedPreferences(this); theSwitch.setChecked(pref.getBoolean("taskbar_active", false)); theSwitch.setOnCheckedChangeListener((compoundButton, b) -> { if (b) { if (U.canDrawOverlays(this)) { boolean firstRun = pref.getBoolean("first_run", true); startTaskbarService(); if (firstRun && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !U.isSystemApp(this)) { ApplicationInfo applicationInfo = null; try { applicationInfo = getPackageManager().getApplicationInfo(BuildConfig.APPLICATION_ID, 0); } catch (PackageManager.NameNotFoundException e) { /* Gracefully fail */ } if (applicationInfo != null) { AppOpsManager appOpsManager = (AppOpsManager) getSystemService( Context.APP_OPS_SERVICE); int mode = appOpsManager.checkOpNoThrow(AppOpsManager.OPSTR_GET_USAGE_STATS, applicationInfo.uid, applicationInfo.packageName); if (mode != AppOpsManager.MODE_ALLOWED) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setTitle(R.string.pref_header_recent_apps) .setMessage(R.string.enable_recent_apps) .setPositiveButton(R.string.action_ok, (dialog, which) -> { try { startActivity( new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS)); U.showToastLong(MainActivity.this, R.string.usage_stats_message); } catch (ActivityNotFoundException e) { U.showErrorDialog(MainActivity.this, "GET_USAGE_STATS"); } }).setNegativeButton(R.string.action_cancel, null); AlertDialog dialog = builder.create(); dialog.show(); } } } } else { U.showPermissionDialog(MainActivity.this); compoundButton.setChecked(false); } } else stopTaskbarService(); }); } if (savedInstanceState == null) { if (!getIntent().hasExtra("theme_change")) getFragmentManager().beginTransaction() .replace(R.id.fragmentContainer, new AboutFragment(), "AboutFragment").commit(); else getFragmentManager().beginTransaction() .replace(R.id.fragmentContainer, new AppearanceFragment(), "AppearanceFragment").commit(); } if (!BuildConfig.APPLICATION_ID.equals(BuildConfig.BASE_APPLICATION_ID) && freeVersionInstalled()) { final SharedPreferences pref = U.getSharedPreferences(this); if (!pref.getBoolean("dont_show_uninstall_dialog", false)) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(R.string.settings_imported_successfully).setMessage(R.string.import_dialog_message) .setPositiveButton(R.string.action_uninstall, (dialog, which) -> { pref.edit().putBoolean("uninstall_dialog_shown", true).apply(); try { startActivity(new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + BuildConfig.BASE_APPLICATION_ID))); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } }); if (pref.getBoolean("uninstall_dialog_shown", false)) builder.setNegativeButton(R.string.action_dont_show_again, (dialogInterface, i) -> pref.edit() .putBoolean("dont_show_uninstall_dialog", true).apply()); AlertDialog dialog = builder.create(); dialog.show(); dialog.setCancelable(false); } if (!pref.getBoolean("uninstall_dialog_shown", false)) { if (theSwitch != null) theSwitch.setChecked(false); SharedPreferences.Editor editor = pref.edit(); String iconPack = pref.getString("icon_pack", BuildConfig.BASE_APPLICATION_ID); if (iconPack.contains(BuildConfig.BASE_APPLICATION_ID)) { editor.putString("icon_pack", BuildConfig.APPLICATION_ID); } else { U.refreshPinnedIcons(this); } editor.putBoolean("first_run", true); editor.apply(); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { ShortcutManager shortcutManager = getSystemService(ShortcutManager.class); if (shortcutManager.getDynamicShortcuts().size() == 0) { Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClass(this, StartTaskbarActivity.class); intent.putExtra("is_launching_shortcut", true); ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "start_taskbar") .setShortLabel(getString(R.string.start_taskbar)) .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_start)).setIntent(intent) .build(); Intent intent2 = new Intent(Intent.ACTION_MAIN); intent2.setClass(this, ShortcutActivity.class); intent2.putExtra("is_launching_shortcut", true); ShortcutInfo shortcut2 = new ShortcutInfo.Builder(this, "freeform_mode") .setShortLabel(getString(R.string.pref_header_freeform)) .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon_freeform)) .setIntent(intent2).build(); shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut, shortcut2)); } } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Creates a application informative dialog with options to * uninstall/launch or cancel.// w w w. j ava2 s. c o m * * @param context * @param appPackage */ public static void appInfo_getLaunchUninstallDialog(final Context context, String appPackage) { try { final PackageManager packageManager = context.getPackageManager(); final PackageInfo app = packageManager.getPackageInfo(appPackage, PackageManager.GET_META_DATA); AlertDialog dialog = new AlertDialog.Builder(context).create(); dialog.setTitle(app.applicationInfo.loadLabel(packageManager)); String description = null; if (app.applicationInfo.loadDescription(packageManager) != null) { description = app.applicationInfo.loadDescription(packageManager).toString(); } String msg = app.applicationInfo.loadLabel(packageManager) + "\n\n" + "Version " + app.versionName + " (" + app.versionCode + ")" + "\n" + (description != null ? (description + "\n") : "") + app.applicationInfo.sourceDir + "\n" + appInfo_getSize(app.applicationInfo.sourceDir); dialog.setMessage(msg); dialog.setCancelable(true); dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Uninstall", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent intent = new Intent(Intent.ACTION_DELETE); intent.setData(Uri.parse("package:" + app.packageName)); context.startActivity(intent); } }); dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Launch", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Intent i = packageManager.getLaunchIntentForPackage(app.packageName); context.startActivity(i); } }); dialog.show(); } catch (Exception e) { if (LOG_ENABLE) { Log.e(TAG, "Dialog could not be made for the specified application '" + appPackage + "'. [" + e.getMessage() + "].", e); } } }
From source file:cm.aptoide.pt.MainActivity.java
public void showAbout() { View aboutView = LayoutInflater.from(this).inflate(R.layout.dialog_about, null); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this).setView(aboutView); final AlertDialog aboutDialog = dialogBuilder.create(); aboutDialog.setIcon(android.R.drawable.ic_menu_help); aboutDialog.setTitle(getString(R.string.about)); aboutDialog.setCancelable(true); WindowManager.LayoutParams params = aboutDialog.getWindow().getAttributes(); params.width = WindowManager.LayoutParams.MATCH_PARENT; aboutDialog.getWindow().setAttributes(params); aboutDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.btn_chlog), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Uri uri = Uri.parse(getString(R.string.change_log_url)); startActivity(new Intent(Intent.ACTION_VIEW, uri)); }/*from w ww . jav a2 s. c o m*/ }); aboutDialog.show(); }
From source file:cm.aptoide.pt.MainActivity.java
public void showFollow() { View socialNetworksView = LayoutInflater.from(this).inflate(R.layout.dialog_social_networks, null); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this).setView(socialNetworksView); final AlertDialog socialDialog = dialogBuilder.create(); socialDialog.setIcon(android.R.drawable.ic_menu_share); socialDialog.setTitle(getString(R.string.social_networks)); socialDialog.setCancelable(true); Button facebookButton = (Button) socialNetworksView.findViewById(R.id.find_facebook); facebookButton.setOnClickListener(new View.OnClickListener() { @Override/* w w w . j a v a 2 s .com*/ public void onClick(View v) { if (isAppInstalled("com.facebook.katana")) { Intent sharingIntent; try { getPackageManager().getPackageInfo("com.facebook.katana", 0); sharingIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/225295240870860")); startActivity(sharingIntent); } catch (NameNotFoundException e) { e.printStackTrace(); } } else { Intent intent = new Intent(mContext, WebViewFacebook.class); startActivity(intent); } } }); Button twitterButton = (Button) socialNetworksView.findViewById(R.id.follow_twitter); twitterButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (isAppInstalled("com.twitter.android")) { String url = "http://www.twitter.com/aptoide"; Intent twitterIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); startActivity(twitterIntent); } else { Intent intent = new Intent(mContext, WebViewTwitter.class); startActivity(intent); } } }); socialDialog.show(); }
From source file:cm.aptoide.pt.MainActivity.java
private void displayOptionsDialog() { final SharedPreferences sPref = PreferenceManager.getDefaultSharedPreferences(this); final Editor editor = sPref.edit(); View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_order_popup, null); AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(view); final AlertDialog orderDialog = dialogBuilder.create(); orderDialog.setIcon(android.R.drawable.ic_menu_sort_by_size); orderDialog.setTitle(getString(R.string.menu_display_options)); orderDialog.setCancelable(true); final RadioButton ord_rct = (RadioButton) view.findViewById(R.id.org_rct); final RadioButton ord_abc = (RadioButton) view.findViewById(R.id.org_abc); final RadioButton ord_rat = (RadioButton) view.findViewById(R.id.org_rat); final RadioButton ord_dwn = (RadioButton) view.findViewById(R.id.org_dwn); final RadioButton ord_price = (RadioButton) view.findViewById(R.id.org_price); final RadioButton btn1 = (RadioButton) view.findViewById(R.id.shw_ct); final RadioButton btn2 = (RadioButton) view.findViewById(R.id.shw_all); final ToggleButton adult = (ToggleButton) view.findViewById(R.id.adultcontent_toggle); orderDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() { boolean pop_change = false; private boolean pop_change_category = false; public void onClick(DialogInterface dialog, int which) { if (ord_rct.isChecked()) { pop_change = true;/* ww w.ja va2s . co m*/ order = Order.DATE; } else if (ord_abc.isChecked()) { pop_change = true; order = Order.NAME; } else if (ord_rat.isChecked()) { pop_change = true; order = Order.RATING; } else if (ord_dwn.isChecked()) { pop_change = true; order = Order.DOWNLOADS; } else if (ord_price.isChecked()) { pop_change = true; order = Order.PRICE; } if (btn1.isChecked()) { pop_change = true; pop_change_category = true; editor.putBoolean("orderByCategory", true); } else if (btn2.isChecked()) { pop_change = true; pop_change_category = true; editor.putBoolean("orderByCategory", false); } if (adult.isChecked()) { pop_change = true; editor.putBoolean("matureChkBox", false); } else { editor.putBoolean("matureChkBox", true); } if (pop_change) { editor.putInt("order_list", order.ordinal()); editor.commit(); if (pop_change_category) { if (!depth.equals(ListDepth.CATEGORY1) && !depth.equals(ListDepth.STORES)) { if (depth.equals(ListDepth.APPLICATIONS)) { removeLastBreadCrumb(); } removeLastBreadCrumb(); depth = ListDepth.CATEGORY1; } } redrawAll(); refreshAvailableList(true); } } }); if (sPref.getBoolean("orderByCategory", false)) { btn1.setChecked(true); } else { btn2.setChecked(true); } if (!ApplicationAptoide.MATURECONTENTSWITCH) { adult.setVisibility(View.GONE); view.findViewById(R.id.dialog_adult_content_label).setVisibility(View.GONE); } adult.setChecked(!sPref.getBoolean("matureChkBox", false)); // adult.setOnCheckedChangeListener(adultCheckedListener); switch (order) { case DATE: ord_rct.setChecked(true); break; case DOWNLOADS: ord_dwn.setChecked(true); break; case NAME: ord_abc.setChecked(true); break; case RATING: ord_rat.setChecked(true); break; case PRICE: ord_price.setChecked(true); break; default: break; } orderDialog.show(); }
From source file:cm.aptoide.pt.MainActivity.java
private void requestUpdateSelf() { View simpleView = LayoutInflater.from(mContext).inflate(R.layout.dialog_simple_layout, null); Builder dialogBuilder = new AlertDialog.Builder(mContext).setView(simpleView); final AlertDialog updateSelfDialog = dialogBuilder.create(); updateSelfDialog.setTitle(getText(R.string.update_self_title)); updateSelfDialog.setIcon(R.drawable.icon_brand_aptoide); TextView message = (TextView) simpleView.findViewById(R.id.dialog_message); message.setText(getString(R.string.update_self_msg, ApplicationAptoide.MARKETNAME)); updateSelfDialog.setCancelable(false); updateSelfDialog.setButton(Dialog.BUTTON_POSITIVE, getString(android.R.string.yes), new Dialog.OnClickListener() { @Override/*from www.java 2s. co m*/ public void onClick(DialogInterface arg0, int arg1) { new DownloadSelfUpdate().execute(); } }); updateSelfDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.no), new Dialog.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); } }); updateSelfDialog.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/*from ww w . jav a2 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:it.unipr.ce.dsg.gamidroid.activities.NAM4JAndroidActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); context = this; isTablet = Utils.isTablet(this); // Setting the default network sharedPreferences = getSharedPreferences(Constants.PREFERENCES, Context.MODE_PRIVATE); Editor editor = sharedPreferences.edit(); editor.putString(Constants.NETWORK, Constants.DEFAULT_NETWORK); editor.commit();//from ww w . jav a2s. c o m // Starting the resources monitoring service startService(new Intent(this, DeviceMonitorService.class)); wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); // Settings menu elements ArrayList<MenuListElement> listElements = new ArrayList<MenuListElement>(); listElements.add(new MenuListElement(getResources().getString(R.string.connectMenuTitle), getResources().getString(R.string.connectMenuSubTitle))); listElements.add(new MenuListElement(getResources().getString(R.string.settingsMenuTitle), getResources().getString(R.string.settingsMenuSubTitle))); listElements.add(new MenuListElement(getResources().getString(R.string.exitMenuTitle), getResources().getString(R.string.exitMenuSubTitle))); listView = (ListView) findViewById(R.id.ListViewContent); MenuListAdapter adapter = new MenuListAdapter(this, R.layout.menu_list_view_row, listElements); listView.setAdapter(adapter); listView.setOnItemClickListener(new ListItemClickListener()); mainRL = (RelativeLayout) findViewById(R.id.rlContainer); listRL = (RelativeLayout) findViewById(R.id.listContainer); cpuBar = (LinearLayout) findViewById(R.id.CpuBar); memoryBar = (LinearLayout) findViewById(R.id.MemoryBar); titleBarRL = (RelativeLayout) findViewById(R.id.titleLl); // Adding swipe gesture listener to the top bar titleBarRL.setOnTouchListener(new SwipeAndClickListener()); menuButton = (Button) findViewById(R.id.menuButton); menuButton.setOnTouchListener(new SwipeAndClickListener()); infoButton = (Button) findViewById(R.id.infoButton); infoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog dialog = new AlertDialog(NAM4JAndroidActivity.this) { @Override public boolean dispatchTouchEvent(MotionEvent event) { dismiss(); return false; } }; String text = getResources().getString(R.string.aboutApp); String title = getResources().getString(R.string.nam4j); dialog.setMessage(text); dialog.setTitle(title); dialog.setCanceledOnTouchOutside(true); dialog.show(); } }); centerButton = (Button) findViewById(R.id.centerButton); centerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { centerMap(); } }); isTablet = Utils.isTablet(context); int[] screenSize = Utils.getScreenSize(context, getWindow()); screenWidth = screenSize[0]; screenHeight = screenSize[1]; // Updates the display orientation each time the device is rotated if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { screenOrientation = Orientation.LANDSCAPE; } else { screenOrientation = Orientation.PORTRAIT; } // If the device is portrait, the menu button is displayed, the menu is // hidden and the swipe listener is added to the menu bar if (screenOrientation == Orientation.PORTRAIT) { menuButton.setVisibility(View.VISIBLE); // Adding swipe gesture listener to the top bar titleBarRL.setOnTouchListener(new SwipeAndClickListener()); if (isTablet) { menuWidth = 0.35; } else { menuWidth = 0.6; } } else { // If the device is a tablet in landscape, the menu button is // hidden, the menu is displayed, the swipe listener is not added to // the menu bar and the mainRL width is set to the window's width // minus the menu's width if (isTablet) { menuWidth = 0.2; menuButton.setVisibility(View.INVISIBLE); RelativeLayout.LayoutParams menuListLP = (LayoutParams) mainRL.getLayoutParams(); // Setting the main view width as the container width without // the menu menuListLP.width = (int) (screenWidth * (1 - menuWidth)); mainRL.setLayoutParams(menuListLP); displaySideMenu(); } else { menuWidth = 0.4; menuButton.setVisibility(View.VISIBLE); // Adding swipe gesture listener to the top bar titleBarRL.setOnTouchListener(new SwipeAndClickListener()); } } // Check if the device has the Google Play Services installed and // updated. They are necessary to use Google Maps int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context); if (code != ConnectionResult.SUCCESS) { showErrorDialog(code); System.out.println("Google Play Services error"); FrameLayout fl = (FrameLayout) findViewById(R.id.frameId); fl.removeAllViews(); } else { // Create a new global location parameters object mLocationRequest = new LocationRequest(); // Set the update interval mLocationRequest.setInterval(LocationUtils.UPDATE_INTERVAL_IN_MILLISECONDS); // Use high accuracy mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); // Set the interval ceiling to one minute mLocationRequest.setFastestInterval(LocationUtils.FAST_INTERVAL_CEILING_IN_MILLISECONDS); bitmapDescriptorBlue = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE); blueCircle = BitmapDescriptorFactory .fromBitmap(BitmapFactory.decodeResource(context.getResources(), R.drawable.blue_circle)); bitmapDescriptorRed = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED); // Create a new location client, using the enclosing class to handle // callbacks mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this) .addOnConnectionFailedListener(this).addApi(LocationServices.API).build(); map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.mapview)).getMap(); if (map != null) { // Set default map center and zoom on Parma double lat = 44.7950156; double lgt = 10.32547; map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(lat, lgt), 12.0f)); // Adding listeners to the map respectively for zoom level // change and onTap event map.setOnCameraChangeListener(getCameraChangeListener()); map.setOnMapClickListener(getOnMapClickListener()); // Set map type as normal (i.e. not the satellite view) map.setMapType(com.google.android.gms.maps.GoogleMap.MAP_TYPE_NORMAL); // Hide traffic layer map.setTrafficEnabled(false); // Enable the 'my-location' layer, which continuously draws an // indication of a user's current location and bearing, and // displays UI controls that allow the interaction with the // location itself // map.setMyLocationEnabled(true); ml = new HashMap<String, Marker>(); // Get file manager for config files fileManager = FileManager.getFileManager(); fileManager.createFiles(); map.setOnMarkerClickListener(this); } else { AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setMessage("The map cannot be initialized."); dialog.setCancelable(true); dialog.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); dialog.show(); } } }