This question already has answers here:
Java equivalent to #region in C#
(24 answers)
Closed 6 years ago.
in .net you have Regions that you can collapse and remove lots of code down to one line.
is there something like this in Android / Java / Eclipse.
#Region "Initialize"
private void DisplayHome(){
Intent i = new Intent(this, SMSInternetActivity.class);
finish();
startActivity(i);
}
private void DisplaySettings(){
Intent i = new Intent(this, DisplaySettings.class);
finish();
startActivity(i);
}
This just being an example..
#End Region
Using Android Studio:
//region "Initialize"
private void DisplayHome(){
Intent i = new Intent(this, SMSInternetActivity.class);
finish();
startActivity(i);
}
private void DisplaySettings(){
Intent i = new Intent(this, DisplaySettings.class);
finish();
startActivity(i);
}
//endregion
There's a plug-in for that! It is called Coffee-Bytes. It is not in active development, but there are some programmers out there that are keeping the functionality going by updating it for new Eclipse releases.
There's two places where you can get the most latest install for Eclipse 3.7 (Indigo):
http://code.google.com/p/academic-cloud/downloads/detail?name=eclipse-folding-plugin.tar.gz&can=2&q=
http://kosiara87.blogspot.com/2011/12/how-to-install-coffee-bytes-plugin-in.html
Basically, you download the archive, then unpack it. Then you copy the feature from the features folder into your Eclipse installation in the Eclipse features folder. Do the same thing with the JAR found in the plugins folder, it goes into your Eclipse plugins folder. Then restart Eclipse.
There's a good SO answer that shows how to set it up:
How to use Coffee-Bytes code folding
Note that you may have to restart Eclipse for this new style of code folding to start working. Enjoy!
You can use Intellij's feature for code folding using //region and //endregion. Works great in Android Studio. However for Eclipse, you'll need a plugin to do that.
Source: Taken from Answer of Alexander Bezrodniy
I believe this is a feature of the IDE i.e. Visual Studio, not .NET in general. You, in theory, can write a plugin for Eclipse that can collapse region in Java code. Eclipse already have the ability to collapse imports and functions.
You need to perform the "surround with" operation (default key combination is CTRL+ALT+T), which allows you to use one of 2 ways to specify code as a region:
editor-fold:
//<editor-fold desc="Description">
code
//</editor-fold>
region & endregion :
//region Description
code
//endregion
As I remember, you must choose one of them to be used for the whole project. Maybe I'm wrong and it's only for a single file (and maybe there isn't a restriction at all).
yes, and the fastest way to do it in Android Studio
highlight the code you want to surround it
press ctrl + alt + t
press c ==> then enter the description
enjoy
Related
Has anyone else tried to mark their clipboard copied data as sensitive as per the following recommendation?
https://developer.android.com/about/versions/13/features/copy-paste
clipData.apply {
description.extras = PersistableBundle().apply {
putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true)
}
}
When I tried to do so, I don't find a clipData.apply method.
How can I set the sensitivity settings in an android app Java code?
apply() is a Kotlin scope function. You appear to be programming in Java, so the Kotlin syntax will not work for you.
By eyeball, the Java equivalent would be:
PersistableBundle extras = new PersistableBundle();
extras.putBoolean(ClipDescription.EXTRA_IS_SENSITIVE, true);
clipData.getDescription().setExtras(extras);
I am working with SpeechRecognizer. The problem was if there is no active internet connection SpeechRecognizer will throw error SpeechRecognizer.ERROR_NETWORK or SpeechRecognizer.ERROR_SERVER.
This is my RecognizerIntent
final Intent recognizerIntent;
recognizerIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, this.getPackageName());
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 5);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);
And I put recognizerIntent.putExtra(RecognizerIntent.EXTRA_PREFER_OFFLINE, true);
But no luck. again it will throw the same error.
And I got these 2 errors frequently.
SpeechRecognizer.ERROR_RECOGNIZER_BUSY
SpeechRecognizer.ERROR_NO_MATCH
Please help me.
First of all, you need to make sure if you have offline package of language you put to EXTRA_LANGUAGE_PREFERENCE installed on the device.
To enable Offline Speech input in supported devices, follow below steps:
Go to Settings
Click on “Language and input”
On-screen keyboard
Select Google voice typing
Select Offline speech recognition
Install desired language
If it still does not work offline, try to change your EXTRA_LANGUAGE_PREFERENCE value to something more specific, "en-US" for example (That did the trick for me)
And also, if you want to tell SpeechRecognizer wich language it should recognize, I guess you should use EXTRA_LANGUAGE parameter instead of EXTRA_LANGUAGE_PREFERENCE
Hope it will help
What have I done so far:
I am currenctly facing some problems with the launchers.
My application adds shortcuts to the workspace of the launcher (homescreen).
But on some devices (Samsum Duos) for example, the titles and /or icons
are changed back after reboot to my default application one.
So I am currently going through 1000s of lines code in the android
source to identify the problem, but was not able to find it.
I saw in InstallShortcutReceiver
a comment in line 183 that the "name" provided by Intent.EXTRA_SHORTCUT_NAME can in
some situations be used only for comparison etc and will be replaced
with the applications default name.
// This name is only used for comparisons and notifications, so fall back to activity name
// if not supplied
But (my Samsum Duos is rooted) I could find the complete information's
about the cell position and shortcutInfo's inside of the launcher.db.
So it was not gone, after reboot, but maybe only not correct initialized!
First Question:
Does anybody know the reason for a custom, programmatically created shortcut to change the title and or icon back to the application's one that created it?
Next story:
I noticed that this issue was reproducible on my Samsum Duos, so I decided
to exclude the Devices Launcher from my "save launcher" list.
To receive the default launcher I am doing the following:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
ResolveInfo resolveInfo = null;
try {
resolveInfo = context.getPackageManager().resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); //can return null!
}catch(RuntimeException e){
ExceptionHandler.logAndSendException(e);//package manager has died
return false;
}
But the problem now is, that it always returns that the default launchers
package is: com.android.launcher2.Launcher, which would be the standard
android stock launcher. But I know that Samsum uses the TouchWiz home
launcher, whos Package is located under com.sec.android.app.launcher!
That is also where I found the launcher.db and all its ShortcutInfo's.
2. Second Question
How do I get reproducible the correct default launcher package to identify
which launcher is used?
edit:
I kind of fixed the second problem. Somehow the ResolveInfo I get from
the PackageManager seems to be not reliable.
For the Samsum Duos I get:
resolveInfo.activityInfo.name = com.android.launcher2.Launcher
resolveInfo.activityInfo.packageName = com.sec.android.app.launcher //this is what I need
But for the Redmi MIUI:
resolveInfo.activityInfo.name = com.miui.home.launcher.Launcher //this time I would need this
resolveInfo.activityInfo.packageName = com.miui.home //the packageName is not complete!
I need an unique identifier for the launcher! So I thought activityInfo.name would be the
way to go, but it isn't in some situations. And the packageManager seems to apply to too many devices. Any suggestions?
Cheers!
I want to create an application which will have:
a text field that will take input from the user, and
a button, which, when clicked, will open a calendar application that is already available in the phone; then, the input text will be added as a note to the selected date.
How can this be done? Is it even possible to do this? If not, how can I display a calendar in my application? I guess this may be a layman's question, but I have just started up with Android programming. Also, I am planning to make the app using HTML, CSS and Javascript. Is it ok to go with it? or is it easier to use only Java and XML files?
I don't know about Calendar application. Here is an example how to start Dropbox app:
Intent intent = getPackageManager().getLaunchIntentForPackage("com.dropbox.android");
intent.addCategory(Intent.CATEGORY_LAUNCHER);
try
{
startActivity(intent);
}
catch (Exception ex)
{
}
You should do something similar for Calendar. Maybe you can provide additional params to intent to make your note insterted into specific date.
Go with Java and XML which i prefer, And about HTML,CSS and Javascripte you can use these if you are developing app using Phonegap.
About your application you can have customize calendar in android you can find many example.
I'm having some problems here with basic Activity starting
I've tried to use the method below:
private void startAC() {
Intent i = new Intent(this, WordSendingActivity.class);
startActivity(i);
}
And while debugging I got some "Source not found" errors which claim that the source attachment does not contain the source for the file: Instrumentation.class, InvocationTargetException.class, Binder.class (in this order)
I got these different class names by trying Run->Step Return
What am I doing wrong here? I just want to preform a basic activity start, how would you do it better?
took me hours to give up my pride and come here :)
I hope my question is clear enough...
It looks like you might be attempting to "Step Return" into built-in classes. Android classes don't have sources available for debugging. They are binary-only classes in the respective android.jar.
The code for starting the activity looks fine. Are you sure you added WordSendingActivity to the AndroidManifest.xml ?