List of usage examples for android.app Activity getResources
@Override
public Resources getResources()
From source file:au.com.infiniterecursion.vidiom.utils.PublishingUtils.java
public Thread videoUploadToVideoBin(final Activity activity, final Handler handler, final String video_absolutepath, final String title, final String description, final String emailAddress, final long sdrecord_id) { Log.d(TAG, "doPOSTtoVideoBin starting"); // Make the progress bar view visible. ((VidiomActivity) activity).startedUploading(PublishingUtils.TYPE_VB); final Resources res = activity.getResources(); Thread t = new Thread(new Runnable() { public void run() { // Do background task. boolean failed = false; HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); URI url = null;/*from w ww . j a va 2s .c o m*/ try { url = new URI(res.getString(R.string.http_videobin_org_add)); } catch (URISyntaxException e) { // Ours is a fixed URL, so not likely to get here. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_VB); e.printStackTrace(); return; } HttpPost post = new HttpPost(url); MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); File file = new File(video_absolutepath); entity.addPart(res.getString(R.string.video_bin_API_videofile), new FileBody(file)); try { entity.addPart(res.getString(R.string.video_bin_API_api), new StringBody("1", "text/plain", Charset.forName("UTF-8"))); // title entity.addPart(res.getString(R.string.video_bin_API_title), new StringBody(title, "text/plain", Charset.forName("UTF-8"))); // description entity.addPart(res.getString(R.string.video_bin_API_description), new StringBody(description, "text/plain", Charset.forName("UTF-8"))); } catch (IllegalCharsetNameException e) { // error e.printStackTrace(); failed = true; } catch (UnsupportedCharsetException e) { // error e.printStackTrace(); return; } catch (UnsupportedEncodingException e) { // error e.printStackTrace(); failed = true; } post.setEntity(entity); // Here we go! String response = null; try { response = EntityUtils.toString(client.execute(post).getEntity(), "UTF-8"); } catch (ParseException e) { // error e.printStackTrace(); failed = true; } catch (ClientProtocolException e) { // error e.printStackTrace(); failed = true; } catch (IOException e) { // error e.printStackTrace(); failed = true; } client.getConnectionManager().shutdown(); // CHECK RESPONSE FOR SUCCESS!! if (!failed && response != null && response.matches(res.getString(R.string.video_bin_API_good_re))) { // We got back HTTP response with valid URL Log.d(TAG, " video bin got back URL " + response); } else { Log.d(TAG, " video bin got eror back:\n" + response); failed = true; } if (failed) { // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_VB); handler.postDelayed(new Runnable() { public void run() { // Update UI // Indicate back to calling activity the result! // update uploadInProgress state also. ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_videobin_org_failed_)); } }, 0); return; } // XXX Convert to preference for auto-email on videobin post // XXX ADD EMAIL NOTIF to all other upload methods // stuck on YES here, if email is defined. if (emailAddress != null && response != null) { // EmailSender through IR controlled gmail system. SSLEmailSender sender = new SSLEmailSender( activity.getString(R.string.automatic_email_username), activity.getString(R.string.automatic_email_password)); // consider // this // public // knowledge. try { sender.sendMail(activity.getString(R.string.vidiom_automatic_email), // subject.getText().toString(), activity.getString(R.string.url_of_hosted_video_is_) + " " + response, // body.getText().toString(), activity.getString(R.string.automatic_email_from), // from.getText().toString(), emailAddress // to.getText().toString() ); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } } // Log record of this URL in POSTs table dbutils.creatHostDetailRecordwithNewVideoUploaded(sdrecord_id, res.getString(R.string.http_videobin_org_add), response, ""); mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_VB); // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. handler.postDelayed(new Runnable() { public void run() { // Update UI // Indicate back to calling activity the result! // update uploadInProgress state also. ((VidiomActivity) activity).finishedUploading(true); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_videobin_org_succeeded_)); } }, 0); } }); t.start(); return t; }
From source file:net.tjado.passwdsafe.PasswdSafeOpenFileFragment.java
public void setOverflowButton(final Activity activity) { final String overflowDescription = activity.getString(R.string.abc_action_menu_overflow_description); final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver(); viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override//w w w . j a v a 2 s .c om public void onGlobalLayout() { final ArrayList<View> outViews = new ArrayList<View>(); decorView.findViewsWithText(outViews, overflowDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); if (outViews.isEmpty()) { return; } AppCompatImageView overflow = (AppCompatImageView) outViews.get(0); itsOriginalDrawable = overflow.getDrawable(); overflow.setImageDrawable(PasswdSafeUtil.scaleImage( activity.getResources().getDrawable(R.drawable.icon_yubico), 0.09f, getResources())); overflow.setColorFilter(activity.getResources().getColor(R.color.menu_icon_color)); removeOnGlobalLayoutListener(decorView, this); } }); }
From source file:com.amaze.filemanager.fragments.MainFragment.java
public static void launchSMB(final HybridFileParcelable baseFile, final Activity activity) { final Streamer s = Streamer.getInstance(); new Thread() { public void run() { try { /*// w w w . j a v a 2s . c om List<SmbFile> subtitleFiles = new ArrayList<SmbFile>(); // finding subtitles for (Layoutelements layoutelement : LIST_ELEMENTS) { SmbFile smbFile = new SmbFile(layoutelement.getDesc()); if (smbFile.getName().contains(smbFile.getName())) subtitleFiles.add(smbFile); } */ s.setStreamSrc(new SmbFile(baseFile.getPath()), baseFile.getSize()); activity.runOnUiThread(() -> { try { Uri uri = Uri.parse(Streamer.URL + Uri .fromFile(new File(Uri.parse(baseFile.getPath()).getPath())).getEncodedPath()); Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(uri, MimeTypes.getMimeType(baseFile.getPath(), baseFile.isDirectory())); PackageManager packageManager = activity.getPackageManager(); List<ResolveInfo> resInfos = packageManager.queryIntentActivities(i, 0); if (resInfos != null && resInfos.size() > 0) activity.startActivity(i); else Toast.makeText(activity, activity.getResources().getString(R.string.smb_launch_error), Toast.LENGTH_SHORT).show(); } catch (ActivityNotFoundException e) { e.printStackTrace(); } }); } catch (Exception e) { e.printStackTrace(); } } }.start(); }
From source file:com.sabaibrowser.UI.java
public UI(Activity browser, UiController controller) { mActivity = browser;//from w w w. j a va 2 s . c o m mUiController = controller; mTabControl = controller.getTabControl(); Resources res = mActivity.getResources(); mInputManager = (InputMethodManager) browser.getSystemService(Activity.INPUT_METHOD_SERVICE); FrameLayout frameLayout = (FrameLayout) mActivity.getWindow().getDecorView() .findViewById(android.R.id.content); LayoutInflater.from(mActivity).inflate(R.layout.custom_screen, frameLayout); mFixedTitlebarContainer = (FrameLayout) frameLayout.findViewById(R.id.fixed_titlebar_container); mContentView = (FrameLayout) frameLayout.findViewById(R.id.main_content); mCustomViewContainer = (FrameLayout) frameLayout.findViewById(R.id.fullscreen_custom_content); mBlockedElementsContainer = (FrameLayout) frameLayout.findViewById(R.id.blocked_dialog_container); mBubbleMenu = (BubbleMenu) frameLayout.findViewById(R.id.bubble_menu); setImmersiveFullscreen(false); mTitleBar = new TitleBar(mActivity, mUiController, this, mContentView); mTitleBar.setProgress(100); mNavigationBar = mTitleBar.getNavigationBar(); mUrlBarAutoShowManager = new UrlBarAutoShowManager(this); mSwipeContainer = (SwipeRefreshLayout) frameLayout.findViewById(R.id.swipe_container); mSwipeContainer.setColorSchemeColors(browser.getResources().getColor(R.color.primary)); mSwipeContainer.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { mUiController.getCurrentTopWebView().reload(); mSwipeContainer.setRefreshing(false); } }); mSwipeContainer.getViewTreeObserver() .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { if (getWebView() == null) return; int scrollY = getWebView().getScrollY(); // workaround for swipetorefresh not "stealing" the scrolling if (scrollY == 0) { mSwipeContainer.setEnabled(true); } else { mSwipeContainer.setEnabled(false); } if (mLastWebViewScrollY < scrollY && mLastWebViewScrollY != 0 && !mTitleBar.isShrank()) { mTitleBar.shrink(); } else if (mLastWebViewScrollY > scrollY && scrollY != 0 && mTitleBar.isShrank()) { mTitleBar.unShrink(); } mLastWebViewScrollY = scrollY; } }); mNavigationBar = mTitleBar.getNavigationBar(); mNavigationBar.setFabMenu(mBubbleMenu); initBubbleMenu(); TypedValue heightValue = new TypedValue(); browser.getTheme().resolveAttribute(android.R.attr.actionBarSize, heightValue, true); mActionBarHeight = TypedValue.complexToDimensionPixelSize(heightValue.data, browser.getResources().getDisplayMetrics()); MainThreadBus.get().register(this); }
From source file:au.com.infiniterecursion.vidiom.utils.PublishingUtils.java
public Thread videoUploadToFTPserver(final Activity activity, final Handler handler, final String latestVideoFile_filename, final String latestVideoFile_absolutepath, final String emailAddress, final long sdrecord_id) { Log.d(TAG, "doVideoFTP starting"); // Make the progress bar view visible. ((VidiomActivity) activity).startedUploading(PublishingUtils.TYPE_FTP); final Resources res = activity.getResources(); Thread t = new Thread(new Runnable() { public void run() { // Do background task. // FTP; connect preferences here! ////from w w w . j a va 2s. c om SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity.getBaseContext()); String ftpHostName = prefs.getString("defaultFTPhostPreference", null); String ftpUsername = prefs.getString("defaultFTPusernamePreference", null); String ftpPassword = prefs.getString("defaultFTPpasswordPreference", null); // use name of local file. String ftpRemoteFtpFilename = latestVideoFile_filename; // FTP FTPClient ftpClient = new FTPClient(); InetAddress uploadhost = null; try { uploadhost = InetAddress.getByName(ftpHostName); } catch (UnknownHostException e1) { // If DNS resolution fails then abort immediately - show // dialog to // inform user first. e1.printStackTrace(); Log.e(TAG, " got exception resolving " + ftpHostName + " - video uploading failed."); uploadhost = null; } if (uploadhost == null) { // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); new AlertDialog.Builder(activity).setMessage(R.string.cant_find_upload_host) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } }, 0); return; } boolean connected = false; try { ftpClient.connect(uploadhost); connected = true; } catch (SocketException e) { e.printStackTrace(); connected = false; } catch (UnknownHostException e) { // e.printStackTrace(); connected = false; } catch (IOException e) { // e.printStackTrace(); connected = false; } if (!connected) { // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); new AlertDialog.Builder(activity).setMessage(R.string.cant_login_upload_host) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } }, 0); return; } boolean reply = false; try { reply = ftpClient.login(ftpUsername, ftpPassword); } catch (IOException e) { // e.printStackTrace(); Log.e(TAG, " got exception on ftp.login - video uploading failed."); } // check the reply code here // If we cant login, abort after showing user a dialog. if (!reply) { try { ftpClient.disconnect(); } catch (IOException e) { // e.printStackTrace(); } // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); new AlertDialog.Builder(activity).setMessage(R.string.cant_login_upload_host) .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).show(); } }, 0); return; } // Set File type to binary try { ftpClient.setFileType(FTP.BINARY_FILE_TYPE); } catch (IOException e) { // e.printStackTrace(); // keep going?! } // BEYOND HERE DONT USE DIALOGS! // Construct the input stream to send to Ftp server, from the // local // video file on the sd card BufferedInputStream buffIn = null; File file = new File(latestVideoFile_absolutepath); try { buffIn = new BufferedInputStream(new FileInputStream(file)); } catch (FileNotFoundException e) { // e.printStackTrace(); Log.e(TAG, " got exception on local video file - video uploading failed."); // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); } }, 0); // This is a bad error, lets abort. // user dialog ?! shouldnt happen, but still... return; } ftpClient.enterLocalPassiveMode(); try { // UPLOAD THE LOCAL VIDEO FILE. ftpClient.storeFile(ftpRemoteFtpFilename, buffIn); } catch (IOException e) { // e.printStackTrace(); Log.e(TAG, " got exception on storeFile - video uploading failed."); // This is a bad error, lets abort. // user dialog ?! shouldnt happen, but still... // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); } }, 0); return; } try { buffIn.close(); } catch (IOException e) { // e.printStackTrace(); Log.e(TAG, " got exception on buff.close - video uploading failed."); // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); } }, 0); return; } try { ftpClient.logout(); } catch (IOException e) { // e.printStackTrace(); Log.e(TAG, " got exception on ftp logout - video uploading failed."); // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); } }, 0); return; } try { ftpClient.disconnect(); } catch (IOException e) { // e.printStackTrace(); Log.e(TAG, " got exception on ftp disconnect - video uploading failed."); // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); handler.postDelayed(new Runnable() { public void run() { // Update UI // Hide the progress bar ((VidiomActivity) activity).finishedUploading(false); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_failed_)); } }, 0); return; } if (emailAddress != null && ftpHostName != null) { // EmailSender through IR controlled gmail system. SSLEmailSender sender = new SSLEmailSender( activity.getString(R.string.automatic_email_username), activity.getString(R.string.automatic_email_password)); // consider // this // public // knowledge. try { sender.sendMail(activity.getString(R.string.vidiom_automatic_email), // subject.getText().toString(), activity.getString(R.string.url_of_hosted_video_is_) + " " + ftpHostName, // body.getText().toString(), activity.getString(R.string.automatic_email_from), // from.getText().toString(), emailAddress // to.getText().toString() ); } catch (Exception e) { Log.e(TAG, e.getMessage(), e); } } // Log record of this URL in POSTs table dbutils.creatHostDetailRecordwithNewVideoUploaded(sdrecord_id, ftpHostName, ftpHostName, ""); mainapp.removeSDFileRecordIDfromUploadingTrack(sdrecord_id, TYPE_FTP); // Use the handler to execute a Runnable on the // main thread in order to have access to the // UI elements. handler.postDelayed(new Runnable() { public void run() { // Update UI // Indicate back to calling activity the result! // update uploadInProgress state also. ((VidiomActivity) activity).finishedUploading(true); ((VidiomActivity) activity) .createNotification(res.getString(R.string.upload_to_ftp_host_succeeded_)); } }, 0); } }); t.start(); return t; }
From source file:org.chromium.chrome.browser.payments.ui.PaymentRequestUI.java
/** * Prepares the PaymentRequestUI for initial display. * * TODO(dfalcantara): Ideally, everything related to the request and its views would just be put * into its own class but that'll require yanking out a lot of this class. * * @param activity Activity displaying the UI. * @param title Title of the page. * @param origin Host of the page.//from w w w . j av a 2 s . c o m * @param canAddCards Whether new cards can be added. */ private void prepareRequestView(Activity activity, String title, String origin, boolean canAddCards) { mSpinnyLayout = mRequestView.findViewById(R.id.payment_request_spinny); // Indicate that we're preparing the dialog for display. TextView messageView = (TextView) mRequestView.findViewById(R.id.message); messageView.setText(R.string.payments_loading_message); ((TextView) mRequestView.findViewById(R.id.page_title)).setText(title); ((TextView) mRequestView.findViewById(R.id.hostname)).setText(origin); // Set up the buttons. mCloseButton = mRequestView.findViewById(R.id.close_button); mCloseButton.setOnClickListener(this); mPayButton = DualControlLayout.createButtonForLayout(activity, true, activity.getString(R.string.payments_pay_button), this); mEditButton = DualControlLayout.createButtonForLayout(activity, false, activity.getString(R.string.payments_edit_button), this); mButtonBar = (DualControlLayout) mRequestView.findViewById(R.id.button_bar); mButtonBar.setAlignment(DualControlLayout.ALIGN_END); mButtonBar.setStackedMargin( activity.getResources().getDimensionPixelSize(R.dimen.infobar_margin_between_stacked_buttons)); mButtonBar.addView(mPayButton); mButtonBar.addView(mEditButton); // Create all the possible sections. mSectionSeparators = new ArrayList<>(); mPaymentContainer = (ScrollView) mRequestView.findViewById(R.id.option_container); mPaymentContainerLayout = (LinearLayout) mRequestView.findViewById(R.id.payment_container_layout); mOrderSummarySection = new LineItemBreakdownSection(activity, activity.getString(R.string.payments_order_summary_label), this); mShippingSummarySection = new ExtraTextSection(activity, activity.getString(R.string.payments_shipping_summary_label), this); mShippingAddressSection = new OptionSection(activity, activity.getString(R.string.payments_shipping_address_label), this); mShippingOptionSection = new OptionSection(activity, activity.getString(R.string.payments_shipping_option_label), this); mContactDetailsSection = new OptionSection(activity, activity.getString(R.string.payments_contact_details_label), this); mPaymentMethodSection = new OptionSection(activity, activity.getString(R.string.payments_method_of_payment_label), this); // Some sections conditionally allow adding new options. mShippingOptionSection.setCanAddItems(false); mPaymentMethodSection.setCanAddItems(canAddCards); // Add the necessary sections to the layout. mPaymentContainerLayout.addView(mOrderSummarySection, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout)); if (mRequestShipping) { // The shipping breakout sections are only added if they are needed. mPaymentContainerLayout.addView(mShippingSummarySection, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout)); } mPaymentContainerLayout.addView(mPaymentMethodSection, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); if (mRequestContactDetails) { // Contact details are optional, depending on the merchant website. mSectionSeparators.add(new SectionSeparator(mPaymentContainerLayout)); mPaymentContainerLayout.addView(mContactDetailsSection, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); } mRequestView.addOnLayoutChangeListener(new FadeInAnimator()); mRequestView.addOnLayoutChangeListener(new PeekingAnimator()); // Enabled in updatePayButtonEnabled() when the user has selected all payment options. mPayButton.setEnabled(false); }
From source file:com.android.launcher3.Utilities.java
public static void showEditMode(final Activity activity, final ShortcutInfo shortcutInfo) { ContextThemeWrapper theme;//from w w w . j a v a 2 s . c o m final Set<String> setString = new HashSet<String>(); if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustomAPI23); } else { theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustom); } AlertDialog.Builder alert = new AlertDialog.Builder(theme); LinearLayout layout = new LinearLayout(activity.getApplicationContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(100, 0, 100, 100); final ImageView img = new ImageView(activity.getApplicationContext()); Drawable icon = null; if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()) != null) { if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()).equals("NULL")) { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(), Launcher.getLauncher(activity).getDeviceProfile().inv))); } } else { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), Launcher.getIcons().get(shortcutInfo.getTargetComponent().getPackageName())); } } } else { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(), Launcher.getLauncher(Launcher.getLauncherActivity()).getDeviceProfile().inv))); } } img.setImageDrawable(icon); img.setPadding(0, 100, 0, 0); img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showIconPack(activity, shortcutInfo); } }); final EditText titleBox = new EditText(activity.getApplicationContext()); try { Set<String> title = new HashSet<>( Utilities.getTitle(activity, shortcutInfo.getTargetComponent().getPackageName())); for (Iterator<String> it = title.iterator(); it.hasNext();) { String titleApp = it.next(); titleBox.setText(titleApp); } } catch (Exception e) { titleBox.setText(shortcutInfo.title); } titleBox.getBackground().mutate().setColorFilter( ContextCompat.getColor(activity.getApplicationContext(), R.color.colorPrimary), PorterDuff.Mode.SRC_ATOP); layout.addView(img); layout.addView(titleBox); alert.setTitle(activity.getApplicationContext().getResources().getString(R.string.edit_label)); alert.setView(layout); alert.setPositiveButton(activity.getApplicationContext().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { for (ItemInfo itemInfo : AllAppsList.data) { if (shortcutInfo.getTargetComponent().getPackageName() .equals(itemInfo.getTargetComponent().getPackageName())) { setString.add(titleBox.getText().toString()); getPrefs(activity.getApplicationContext()).edit() .putStringSet(itemInfo.getTargetComponent().getPackageName(), setString) .apply(); Launcher.getShortcutsCreation().clearAllLayout(); applyChange(activity); } } } }); alert.setNegativeButton(activity.getApplicationContext().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Launcher.getShortcutsCreation().clearAllLayout(); } }); alert.show(); }
From source file:jmri.enginedriver.threaded_application.java
public boolean setActivityOrientation(Activity activity, Boolean webPref) { String to;/*w w w . j a v a 2s.c o m*/ to = prefs.getString("ThrottleOrientation", activity.getApplicationContext().getResources() .getString(R.string.prefThrottleOrientationDefaultValue)); if (to.equals("Auto-Web")) { int orient = activity.getResources().getConfiguration().orientation; if ((webPref && orient == Configuration.ORIENTATION_PORTRAIT) || (!webPref && orient == Configuration.ORIENTATION_LANDSCAPE)) return (false); } else if (webPref) { to = prefs.getString("WebOrientation", activity.getApplicationContext().getResources() .getString(R.string.prefWebOrientationDefaultValue)); } int co = activity.getRequestedOrientation(); if (to.equals("Landscape") && (co != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); else if (to.equals("Auto-Rotate") && (co != ActivityInfo.SCREEN_ORIENTATION_SENSOR)) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); else if (to.equals("Portrait") && (co != ActivityInfo.SCREEN_ORIENTATION_PORTRAIT)) activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); return true; }
From source file:com.amaze.carbonfilemanager.fragments.MainFragment.java
public static void launchSMB(final SmbFile smbFile, final long si, final Activity activity) { final Streamer s = Streamer.getInstance(); new Thread() { public void run() { try { /*//from w ww. j a va2 s .co m List<SmbFile> subtitleFiles = new ArrayList<SmbFile>(); // finding subtitles for (Layoutelements layoutelement : LIST_ELEMENTS) { SmbFile smbFile = new SmbFile(layoutelement.getDesc()); if (smbFile.getName().contains(smbFile.getName())) subtitleFiles.add(smbFile); } */ s.setStreamSrc(smbFile, si); activity.runOnUiThread(new Runnable() { public void run() { try { Uri uri = Uri.parse(Streamer.URL + Uri.fromFile(new File(Uri.parse(smbFile.getPath()).getPath())) .getEncodedPath()); Intent i = new Intent(Intent.ACTION_VIEW); i.setDataAndType(uri, MimeTypes.getMimeType(new File(smbFile.getPath()))); PackageManager packageManager = activity.getPackageManager(); List<ResolveInfo> resInfos = packageManager.queryIntentActivities(i, 0); if (resInfos != null && resInfos.size() > 0) activity.startActivity(i); else Toast.makeText(activity, activity.getResources().getString(R.string.smb_launch_error), Toast.LENGTH_SHORT).show(); } catch (ActivityNotFoundException e) { e.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } } }.start(); }
From source file:fiskinfoo.no.sintef.fiskinfoo.Implementation.FiskInfoUtility.java
public boolean writeMapLayerToExternalStorage(Activity activity, byte[] data, String writableName, String format, String downloadSavePath, boolean showToasts) { if (FiskInfoUtility.shouldAskPermission()) { String[] perms = { "android.permission.WRITE_EXTERNAL_STORAGE" }; int permsRequestCode = 0x001; // activity.requestPermissions(perms, permsRequestCode); ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, permsRequestCode);/* w w w . j a va 2 s. c o m*/ } String filePath; OutputStream outputStream = null; filePath = downloadSavePath; boolean success = false; String fileEnding = format; File directory = filePath == null ? null : new File(filePath); if (directory != null && !directory.isDirectory() && !directory.mkdirs()) { directory = null; } if (directory == null) { String directoryPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) .toString(); String directoryName = "FiskInfo"; filePath = directoryPath + "/" + directoryName + "/"; new File(filePath).mkdirs(); } if (fileEnding != null && fileEnding.equals(activity.getBaseContext().getString(R.string.olex))) { fileEnding = "olx.gz"; } try { File dir = new File(filePath); File file = new File(filePath + writableName + "." + fileEnding); if (!dir.canWrite()) { Toast.makeText(activity.getBaseContext(), R.string.error_cannot_write_to_directory, Toast.LENGTH_LONG); throw new IOException(activity.getResources().getString(R.string.error_cannot_write_to_directory)); } // index 1 is leef when plugged in. Dirs[1].getAbsoluteFile() is writable // File[] dirs = ContextCompat.getExternalFilesDirs(activity.getBaseContext(), null); outputStream = new FileOutputStream(file); outputStream.write(data); if (showToasts) { Toast.makeText(activity.getBaseContext(), "Fil lagret til " + filePath, Toast.LENGTH_LONG).show(); } success = true; } catch (IOException e) { if (showToasts) { Toast.makeText(activity.getBaseContext(), R.string.disk_write_failed, Toast.LENGTH_LONG).show(); } e.printStackTrace(); } finally { if (outputStream != null) { try { outputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return success; }