Android Studio New Class - android-studio-2.3

When I try to create a new class in Android studio 2.3.3 , I get the error shown in the image below.

Open Setting -> File and Code Templates -> Files -> Class.
Make sure that your class template looks like this
#if (${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end
#if (${IMPORT_BLOCK} != "")${IMPORT_BLOCK}
#end
#parse("File Header.java")
#if (${VISIBILITY} == "PUBLIC")public #end #if (${ABSTRACT} == "TRUE")abstract #end #if (${FINAL} == "TRUE")final #end class ${NAME} #if (${SUPERCLASS} != "")extends ${SUPERCLASS} #end #if (${INTERFACES} != "")implements ${INTERFACES} #end {
}

Related

What is the Objective C equivalent of self.view.traitCollection.horizontalSizeClass?

What is the obj c code for below swift statement?
if (self.view.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClass.Compact)
what i figured out so far is proviede below but it is giving error when i add self.view
if ([self.view UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact])
{
NSLog(#"Compact");
}
Try this
if (self.view.traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact) {
// do your stuff
}
Hope it works

Exclude IStringLocalizer/GetString in Unit testing

I use IstringLocalizer in controller in asp.net core to read shared resources .
In a method i have :
foreach (var category in urlCategories)
{
if (category == _localizer.GetString("CategoryWebshop")) model.SelectedIndustries.Add(1);
else if (category == _localizer.GetString("CategoryStore")) model.SelectedIndustries.Add(2);
else if (category == _localizer.GetString("CategoryWebsite")) model.SelectedIndustries.Add(3);
else if (category == _localizer.GetString("CategoryService")) model.SelectedIndustries.Add(4);
else if (category == _localizer.GetString("CategoryProduction")) model.SelectedIndustries.Add(5);
else if (category == _localizer.GetString("CategoryTrade")) model.SelectedIndustries.Add(6);
else if (category == _localizer.GetString("CategoryRestaurant")) model.SelectedIndustries.Add(7);
else if (category == _localizer.GetString("CategoryRealEstate")) model.SelectedIndustries.Add(8);
}
In unit test GetString of localizer does not let the test to get 100%
How can i fix the problem or skip/exclude that part from testing ?
Thanks

How can I detect if the currently running app was installed from the app store?

Is there a way in iOS to programmatically check if the currently running app was installed from the iOS App Store? This is in contrast to an app that was run via Xcode, TestFlight, or any non-official distribution source.
This is in the context of an SDK that doesn't have access to the app's source code.
To be clear - I am looking for some signature, so to speak, given to the app (presumably by Apple), that will, without dependence on any preprocessor flags or other build configurations, be accessible to any application at run time.
Apps downloaded from the App Store have a iTunesMetadata.plist file added by the store:
NSString *file=[NSHomeDirectory() stringByAppendingPathComponent:#"iTunesMetadata.plist"];
if ([[NSFileManager defaultManager] fileExistsAtPath:file]) {
// probably a store app
}
Perhaps you might want to check if this file exists.
Update:
In iOS8, the application bundle has been moved. According to #silyevsk, the plist is now one level above [the new application main bundle path], at /private/var/mobile/Containers/Bundle/Application/4A74359F-E6CD-44C9-925D-AC82Eā€Œā€Œā€‹ā€‹B5EA837/iTunesMetadata.plist, and unfortunately, this can't be accessed from the app (permission denied)
Update Nov 4th 2015:
It appears that checking the receipt name can help. It must be noted that this solution is slightly different: it doesn't return whether we're running an App Store app, but rather whether we're running a beta Testflight app. This might or might not be useful depending on your context.
On top of that, it's a very fragile solution because the receipt name could change at any time. I'm reporting it anyway, in case you have no other options:
// Objective-C
BOOL isRunningTestFlightBeta = [[[[NSBundle mainBundle] appStoreReceiptURL] lastPathComponent] isEqualToString:#"sandboxReceipt"];
// Swift
let isRunningTestFlightBeta = NSBundle.mainBundle().appStoreReceiptURL?.lastPathComponent=="sandboxReceipt"
Source: Detect if iOS App is Downloaded from Apple's Testflight
How HockeyKit does it
By combining the various checks you can guess whether the app is running in a Simulator, in a Testflight build, or in an AppStore build.
Here's a segment from HockeyKit:
BOOL bit_isAppStoreReceiptSandbox(void) {
#if TARGET_OS_SIMULATOR
return NO;
#else
NSURL *appStoreReceiptURL = NSBundle.mainBundle.appStoreReceiptURL;
NSString *appStoreReceiptLastComponent = appStoreReceiptURL.lastPathComponent;
BOOL isSandboxReceipt = [appStoreReceiptLastComponent isEqualToString:#"sandboxReceipt"];
return isSandboxReceipt;
#endif
}
BOOL bit_hasEmbeddedMobileProvision(void) {
BOOL hasEmbeddedMobileProvision = !![[NSBundle mainBundle] pathForResource:#"embedded" ofType:#"mobileprovision"];
return hasEmbeddedMobileProvision;
}
BOOL bit_isRunningInTestFlightEnvironment(void) {
#if TARGET_OS_SIMULATOR
return NO;
#else
if (bit_isAppStoreReceiptSandbox() && !bit_hasEmbeddedMobileProvision()) {
return YES;
}
return NO;
#endif
}
BOOL bit_isRunningInAppStoreEnvironment(void) {
#if TARGET_OS_SIMULATOR
return NO;
#else
if (bit_isAppStoreReceiptSandbox() || bit_hasEmbeddedMobileProvision()) {
return NO;
}
return YES;
#endif
}
BOOL bit_isRunningInAppExtension(void) {
static BOOL isRunningInAppExtension = NO;
static dispatch_once_t checkAppExtension;
dispatch_once(&checkAppExtension, ^{
isRunningInAppExtension = ([[[NSBundle mainBundle] executablePath] rangeOfString:#".appex/"].location != NSNotFound);
});
return isRunningInAppExtension;
}
Source: GitHub - bitstadium/HockeySDK-iOS - BITHockeyHelper.m
A possible Swift class, based on HockeyKit's class, could be:
//
// WhereAmIRunning.swift
// https://gist.github.com/mvarie/63455babc2d0480858da
//
// ### Detects whether we're running in a Simulator, TestFlight Beta or App Store build ###
//
// Based on https://github.com/bitstadium/HockeySDK-iOS/blob/develop/Classes/BITHockeyHelper.m
// Inspired by https://stackoverflow.com/questions/18282326/how-can-i-detect-if-the-currently-running-app-was-installed-from-the-app-store
// Created by marcantonio on 04/11/15.
//
import Foundation
class WhereAmIRunning {
// MARK: Public
func isRunningInTestFlightEnvironment() -> Bool{
if isSimulator() {
return false
} else {
if isAppStoreReceiptSandbox() && !hasEmbeddedMobileProvision() {
return true
} else {
return false
}
}
}
func isRunningInAppStoreEnvironment() -> Bool {
if isSimulator(){
return false
} else {
if isAppStoreReceiptSandbox() || hasEmbeddedMobileProvision() {
return false
} else {
return true
}
}
}
// MARK: Private
private func hasEmbeddedMobileProvision() -> Bool{
if let _ = NSBundle.mainBundle().pathForResource("embedded", ofType: "mobileprovision") {
return true
}
return false
}
private func isAppStoreReceiptSandbox() -> Bool {
if isSimulator() {
return false
} else {
if let appStoreReceiptURL = NSBundle.mainBundle().appStoreReceiptURL,
let appStoreReceiptLastComponent = appStoreReceiptURL.lastPathComponent
where appStoreReceiptLastComponent == "sandboxReceipt" {
return true
}
return false
}
}
private func isSimulator() -> Bool {
#if arch(i386) || arch(x86_64)
return true
#else
return false
#endif
}
}
Gist: GitHub - mvarie/WhereAmIRunning.swift
Update Dec 9th 2016:
User halileohalilei reports that "This no longer works with iOS10 and Xcode 8.". I didn't verify this, but please check the updated HockeyKit source (see function bit_currentAppEnvironment) at:
Source: GitHub - bitstadium/HockeySDK-iOS - BITHockeyHelper.m
Over time, the above class has been modified and it seems to handle iOS10 as well.
Update Oct 6th 2020:
Hockey has been deprecated/abandoned and replaced by Microsoft's AppCenter SDK.
This is their App Store / Testflight build detection class (link to repository below code):
MSUtility+Environment.h :
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#import <Foundation/Foundation.h>
#import "MSUtility.h"
/*
* Workaround for exporting symbols from category object files.
*/
extern NSString *MSUtilityEnvironmentCategory;
/**
* App environment
*/
typedef NS_ENUM(NSInteger, MSEnvironment) {
/**
* App has been downloaded from the AppStore.
*/
MSEnvironmentAppStore = 0,
/**
* App has been downloaded from TestFlight.
*/
MSEnvironmentTestFlight = 1,
/**
* App has been installed by some other mechanism.
* This could be Ad-Hoc, Enterprise, etc.
*/
MSEnvironmentOther = 99
};
/**
* Utility class that is used throughout the SDK.
* Environment part.
*/
#interface MSUtility (Environment)
/**
* Detect the environment that the app is running in.
*
* #return the MSEnvironment of the app.
*/
+ (MSEnvironment)currentAppEnvironment;
#end
MSUtility+Environment.m :
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
#import "MSUtility+Environment.h"
/*
* Workaround for exporting symbols from category object files.
*/
NSString *MSUtilityEnvironmentCategory;
#implementation MSUtility (Environment)
+ (MSEnvironment)currentAppEnvironment {
#if TARGET_OS_SIMULATOR || TARGET_OS_OSX || TARGET_OS_MACCATALYST
return MSEnvironmentOther;
#else
// MobilePovision profiles are a clear indicator for Ad-Hoc distribution.
if ([self hasEmbeddedMobileProvision]) {
return MSEnvironmentOther;
}
/**
* TestFlight is only supported from iOS 8 onwards and as our deployment target is iOS 8, we don't have to do any checks for
* floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1).
*/
if ([self isAppStoreReceiptSandbox]) {
return MSEnvironmentTestFlight;
}
return MSEnvironmentAppStore;
#endif
}
+ (BOOL)hasEmbeddedMobileProvision {
BOOL hasEmbeddedMobileProvision = !![[NSBundle mainBundle] pathForResource:#"embedded" ofType:#"mobileprovision"];
return hasEmbeddedMobileProvision;
}
+ (BOOL)isAppStoreReceiptSandbox {
#if TARGET_OS_SIMULATOR
return NO;
#else
if (![NSBundle.mainBundle respondsToSelector:#selector(appStoreReceiptURL)]) {
return NO;
}
NSURL *appStoreReceiptURL = NSBundle.mainBundle.appStoreReceiptURL;
NSString *appStoreReceiptLastComponent = appStoreReceiptURL.lastPathComponent;
BOOL isSandboxReceipt = [appStoreReceiptLastComponent isEqualToString:#"sandboxReceipt"];
return isSandboxReceipt;
#endif
}
#end
Source: GitHub - microsoft/appcenter-sdk-apple - MSUtility+Environment.m
If you're talking about your own app, you could add a state that returns true if it was build as part of a Store version (e.g. a compiler conditional) and false in every other case.
If you're talking about another app, it's not easy or straightforward (or maybe not even possible) to query other apps outside of your sandbox.
Since the code by #magma no longer works IOS11.1 Here is a bit of a long winded solution.
We check the app version on the app store and compare it to the version in the Bundle
static func isAppStoreVersion(completion: #escaping (Bool?, Error?) -> Void) throws -> URLSessionDataTask {
guard let info = Bundle.main.infoDictionary,
let currentVersion = info["CFBundleShortVersionString"] as? String,
let identifier = info["CFBundleIdentifier"] as? String else {
throw VersionError.invalidBundleInfo
}
let urlString = "https://itunes.apple.com/gb/lookup?bundleId=\(identifier)"
guard let url = URL(string:urlString) else { throw VersionError.invalidBundleInfo }
let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
do {
if let error = error { throw error }
guard let data = data else { throw VersionError.invalidResponse }
let json = try JSONSerialization.jsonObject(with: data, options: [.allowFragments]) as? [String: Any]
guard let result = (json?["results"] as? [Any])?.first as? [String: Any], let appStoreVersion = result["version"] as? String else {
throw VersionError.invalidResponse
}
completion(appStoreVersion == currentVersion, nil)
} catch {
completion(nil, error)
}
}
task.resume()
return task
}
Called like this
DispatchQueue.global(qos: .background).async {
_ = try? VersionManager.isAppStoreVersion { (appStoreVersion, error) in
if let error = error {
print(error)
} else if let appStoreVersion = appStoreVersion, appStoreVersion == true {
// app store stuf
} else {
// other stuff
}
}
}
enum VersionError: Error {
case invalidResponse, invalidBundleInfo
}
My observation is when a device connected to Xcode, and then we open Organiser, switch to Devices pane it will list all Applications which is not installed from App Store. So what you have to do is download Xcode, then connect your device, go to Devices pane and see which all applications are installed from non-App Store sources. This is the simplest solution.

NullPointerException with Texlipse and Miktex 2.9

When using Texlipse together with Miktex 2.9 on my Windows machine, the system throws a NullPointerExcpetion each time the document is compiled.
The problem disappeared after I have updated the Miktex 2.9 distribution using the Update manager. Hope this helps others who have the same problem.
Regards,
Pwndrian
To me it happens too.
This is a workaround I did, however I think that it is not quite optimal solution.
I saw that there is a bug opened http://sourceforge.net/tracker/?func=detail&aid=3306779&group_id=133306&atid=726818.
There is the class net.sourceforge.texlipse.builder.TExlipseBuilder, I made the following changes to overcome this problem(Please note the differences in both functions). The problem is that in TExlipsePlugin in the function getCurrentProject the actEditor is null since there is no active editor when importing projects or when pressing on clean while no editor is open.
#Override
protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
throws CoreException {
BuilderRegistry.clearConsole();
IWorkbenchPage page = TexlipsePlugin.getCurrentWorkbenchPage();
IEditorPart actEditor = null;
if (page.isEditorAreaVisible()
&& page.getActiveEditor() != null) {
actEditor = page.getActiveEditor();
}
if ( actEditor == null )
return null;
if (isUpToDate(getProject()))
return null;
Object s = TexlipseProperties.getProjectProperty(getProject(), TexlipseProperties.PARTIAL_BUILD_PROPERTY);
if (s != null) {
partialBuild(monitor);
} else {
buildFile(null, monitor);
}
return null;
}
/**
* Clean the temporary files.
*
* #see IncrementalProjectBuilder.clean
*/
#Override
protected void clean(IProgressMonitor monitor) throws CoreException {
IProject project = getProject();
BuilderRegistry.clearConsole();
IWorkbenchPage page = TexlipsePlugin.getCurrentWorkbenchPage();
IEditorPart actEditor = null;
if (page.isEditorAreaVisible()
&& page.getActiveEditor() != null) {
actEditor = page.getActiveEditor();
}
if ( actEditor == null )
return;
// reset session variables
TexlipseProperties.setSessionProperty(project, TexlipseProperties.SESSION_LATEX_RERUN, null);
TexlipseProperties.setSessionProperty(project, TexlipseProperties.SESSION_BIBTEX_RERUN, null);
TexlipseProperties.setSessionProperty(project, TexlipseProperties.BIBFILES_CHANGED, null);
// check main file
String mainFile = TexlipseProperties.getProjectProperty(project, TexlipseProperties.MAINFILE_PROPERTY);
if (mainFile == null || mainFile.length() == 0) {
// main tex file not set -> nothing builded -> nothing to clean
return;
}
cleanTempDir(monitor, project);
cleanOutput(monitor, project);
monitor.subTask(TexlipsePlugin.getResourceString("builderSubTaskCleanMarkers"));
this.deleteMarkers(project);
project.refreshLocal(IProject.DEPTH_INFINITE, monitor);
monitor.done();
}

How can I invoke the Blackberry camera and save the picture that is taken in my code?

I'd like my user to take a picture as an attachment by using the built in camera.
Is there someway to invoke the camera on a button press and save the resulting taken picture?
The other option is to use the BlackBerry Invoke API to start the native camera application and listen for a file system event:
Invoke.invokeApplication(Invoke.APP_TYPE_CAMERA, new CameraArguments());
then, later:
class FileExplorerDemoJournalListener implements FileSystemJournalListener {
public void fileJournalChanged() {
long nextUSN = FileSystemJournal.getNextUSN();
for (long lookUSN = nextUSN - 1; lookUSN >= _lastUSN && msg == null; --lookUSN) {
FileSystemJournalEntry entry = FileSystemJournal.getEntry(lookUSN);
if (entry == null) {
break;
}
String path = entry.getPath();
if (path != null) {
if (path.endsWith("png") || path.endsWith("jpg") || path.endsWith("bmp") || path.endsWith("gif") ){
switch (entry.getEvent()) {
case FileSystemJournalEntry.FILE_ADDED:
//either a picture was taken or a picture was added to the BlackBerry device
break;
case FileSystemJournalEntry.FILE_DELETED:
//a picture was removed from the BlackBerry device;
break;
}
}
}
}
}
}
Finally...
Application.addFileSystemJournalListener(new FileExplorerDemoJournalListener());
This will get you most of the way there... taken from: http://docs.blackberry.com/en/developers/deliverables/11942/Detect_when_img_is_added_or_removed_file_system_740288_11.jsp
http://docs.blackberry.com/en/developers/deliverables/17968/Take_a_picture_in_a_BB_device_app_1228201_11.jsp

Resources