[Tutorial] How to Implement & Retrieve Info | Android Shortcut Manager [API 25+] - Android Software Development

{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
This tutorial is about New Android API called ShortcutManager, introduced in API Level 25.
By ShortcutManager you can design a better User Experience (UX) for Normal Apps & Launcher Apps (Home).
This is very useful API that increases the productivity of Apps & so users. App Shortcuts are the link to inner part of an app.
If your app targets Android 7.1 (API level 25) or higher, you can define shortcuts to specific actions in your app. These shortcuts can be displayed in a supported launcher. Shortcuts let your users quickly start common or recommended tasks within your app.
Read More
Click to expand...
Click to collapse
The ShortcutManager manages an app's shortcuts. Shortcuts provide users with quick access to activities other than an app's main activity in the currently-active launcher. For example, an email app may publish the "compose new email" action, which will directly open the compose activity. The ShortcutInfo class contains information about each of the shortcuts themselves.
Read More
Click to expand...
Click to collapse
List of Geeks Empire Open Source Projects based on Android 7.1.+ AppShortcut API
- Super Shortcut
- Phone App
# Let Start #​
What do you need to get started...
- To Learn: Create Hello World Project
- To Implement: You must have an App with different Activities.
Click to expand...
Click to collapse
What will you learn...
- Creating Launcher App
- Add & Get Info from Shortcut Manager
- Working with List<>
Click to expand...
Click to collapse
Index
- Implement App Shortcut to your App -- Static Shortcuts | Dynamic Shortcuts
- Retrieve ShortcutInfo as Default Launcher App
Thanks for Supporting GeeksEmpire projects​
Don't Forget To Hit Thanks​

Implement AppShortcuts [Static|Dynamic]
You can publish two different types of shortcuts for your app:
- Static shortcuts are defined in a resource file that is packaged into an APK. Therefore, you must wait until you update your entire app to change the details of these static shortcuts.
- Dynamic shortcuts are published at runtime using the ShortcutManager API. During runtime, your app can publish, update, and remove its dynamic shortcuts.
Click to expand...
Click to collapse
# Static Shortcuts
(If you have Camera App, it is reasonable to create static shortcuts to Selfie Activity, Video Recording or etc.)
Like other resources, you need to define Static Shortcuts inside the .xml file under app/res/xml/static_shortcuts_info.xml and call it inside AndroidManifest.xml
Code:
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:shortcutId="some_string_must_be_different_for_each"
android:enabled="true"
android:icon="@drawable/icon"
android:shortcutShortLabel="text"
android:shortcutLongLabel="text"
android:shortcutDisabledMessage="warning_text">
<intent
android:action="android.intent.action.VIEW"
android:targetPackage="com.test.application"
android:targetClass="com.test.application.SomeActivity" />
<!-- If your shortcut is associated with multiple intents, include them here. The last intent in the list determines what the user sees whenthey launch this shortcut. -->
<categories android:name="android.shortcut.conversation" />
</shortcut>
<!-- Add More* -->
</shortcuts>
* Add more AppShortcut is limited to each activity with ACTION_MAIN & LAUNCHER Category in intent filter
Code:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Get limited amount of AppShortcuts (Static/Daynamic combined) with
Code:
getSystemService(ShortcutManager.class).getMaxShortcutCountPerActivity()
after creating Static Shortcuts Info call them inside Manifest as meta-data inside activity tag with mentioned intent filter.
Code:
<activity android:name="Main">
<intent-filter>
<!-- activity with this intent filter can have app shortcut -->
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.shortcuts" android:resource="@xml/static_shortcuts_info.xml" />
</activity>
Done!
# Dynamic Shortcuts
(If you have Online Shopping App, it is reasonable to implement Dynamic Shortcuts to New Available Product, Special Deals Information to show names or prices)
You need to add dynamic shortcuts in runtime. for example @onStart(Bundle){}
Code:
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
List<ShortcutInfo> shortcutInfos = new ArrayList<ShortcutInfo>();
ShortcutInfo firstShortcut = new ShortcutInfo.Builder(getApplicationContext(), "different_text_for_each")
.setShortLabel("Deals")
.setLongLabel("Smartphone 20% Off")
.setIcon(Icon.createWithResource(context, R.drawable.icon_website))
.setIntent(new Intent(context, Activity.class))
.build();
ShortcutInfo secondShortcut = new ShortcutInfo.Builder(getApplicationContext(), "different_text_for_each")
.setShortLabel("NEW Phone")
.setLongLabel("Available April 1st")
.setIcon(Icon.createWithResource(context, R.drawable.icon_website))
.setIntent(new Intent(context, Activity.class))
.build();
shortcutInfos.add(firstShortcut);
shortcutInfos.add(secondShortcut);
shortcutManager.setDynamicShortcuts(shortcutInfos);
//after first time you can just update the value by [B]updateShortcuts(List<ShortcutInfo>)[/B]
You can remove one shortcut by calling removeDynamicShortcuts and set it is specific id (string)
Code:
removeDynamicShortcuts("string_of_id")
Or Just call this method
Code:
removeAllDynamicShortcuts()
Done!

Retrieve AppShortcuts as Launcher App [Default Home]
If you want to develop Launcher App, you can retrieve AppShortcuts Information to show them to your users.
NOTE: Launcher must be set as Default Home App to access this information.
This is simple Launcher Activity Config inside AndroidManifest.xml
Code:
<activity
android:name=".launcher"
android:label="@string/launcher"
android:icon="@drawable/ic_launcher_home"
android:launchMode="singleTask"
android:stateNotNeeded="true"
android:clearTaskOnLaunch="true"
android:theme="@android:style/Theme.DeviceDefault.Wallpaper">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<!-- required intent filter for Launcher App -->
<category android:name="android.intent.category.HOME"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Then you can go to Setting > Apps > Home (Select your Launcher).
So you should add this checkpoint inside your code to check if your app has permission (as default home) to get this info.
Code:
LauncherApps.hasShortcutHostPermission ()
For Launcher there is a special API, added in API 21 but methods for AppShortcuts added in API 25. (LauncherApps API)
Class for retrieving a list of launchable activities for the current user and any associated managed profiles that are visible to the current user, which can be retrieved with getProfiles(). This is mainly for use by launchers. Apps can be queried for each user profile. Since the PackageManager will not deliver package broadcasts for other profiles, you can register for package changes here. Read More
Click to expand...
Click to collapse
You set Package of an App to ShortcutQuery to retrieve info.
This method get all AppShortcuts (Static/Dynamic)
Code:
try {
LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
int queryFlags =
LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC
| LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST
| LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED;
ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(packageName, 0);
List<ShortcutInfo> shortcutInfoList = launcherApps.getShortcuts(
new LauncherApps.ShortcutQuery().setPackage(packageName).setQueryFlags(queryFlags),
UserHandle.getUserHandleForUid(applicationInfo.uid));
for (int i = 0; i < shortcutInfoList.size(); i++){
System.out.println("Shortcut :: " + shortcutInfoList.get(i).getShortLabel());
}
}
catch (Exception e){e.printStackTrace();}
Then it is your choice to design how you want to show it to your users. Simple PopupMenu or ListView...
Done!

Reserved 4

Reserved 5

Kindda looking for it
it really helped me

Update Info
開発者 said:
Kindda looking for it
it really helped me
Click to expand...
Click to collapse
Your Welcome

Related

[GUIDE] Create Transparent Demo pages on Android

Have you seen those apps with the really cool hand drawn arrows that show the users how the app works the first time they run it? Yeah I have too and I wanted to figure out how to do that. So I did. Now I'm going to show you also.
This is going to be pretty easy and we'll do it for Activities and Fragments so all your apps will be covered.
The first thing you'll need to do is draw the pictures that we'll place over the Activity/Fragment. I draw mine on Gimp but you can use whatever drawing tool you want. I recommend you draw them 480 X 760 px. You'll want to set your background as Transparent. Here is a sample of what I've done.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
That's easy enough. I recommend you draw these as you go, I've found that I needed to edit the images to make sure they are pointing to the exact right place on the screen.
Next up we'll create an XML layout for each image that you want to use in your app. We'll create a LinearLayout with an embedded ImageView. The ImageView will display our beautiful art from above. Make sure to give the LinearLayout an ID, set the background to @null. As for the ImageView you'll need to give it an ID also and set the source to the image file you drew previously. Be sure to put the image in the res/drawable folder, make sure the image file name is all lower case and it is a .png file type. Again you will need to create as many of these XML layouts as you did images above.
overlay_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llOverlay_activity"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background= @null"
androidrientation="vertical" >
<ImageView
android:id="@+id/ivOverlayEntertask"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/activity_overlay" />
</LinearLayout>
We are going to control when this is displayed to the user with SharedPreferences. Utilizing SharePreferences gives us the ability to show the tutorial on the first run of the app and also allows the user to see it again by selecting it in the apps Settings menu.
We'll need to create a folder under /res/ named /xml, so you'll end up with /res/xml. Now let's create a new XML layout for our preferences. In Eclipse you'll choose File New > Android XML file. Change the Resource Type to Preference, then name the file exactly this prefs.xml and click Finish.
Next we'll add a CheckBoxPreference with the following attributes:
android:defaultValue="true"
android:key="tutorial"
android:summary="Enable tutorial on device"
android:title="Tutorial"
So your final prefs.xml file will look exactly like this:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:defaultValue="true"
android:key="tutorial"
android:summary="Enable tutorial on device"
android:title="Tutorial" />
</PreferenceScreen>
Now let's look at how to show this to the user from our Activity or Fragment. First we'll determine if our tutorial CheckBoxPreferene is set to true and if so we'll display the drawing on top of the current Activity/Fragment.
Create and instance of SharedPreferences and a boolean to store the value:
SharedPreferences setNoti;
boolean showTut;
Then in our OnCreate we'll get the value for our tutorial CheckBoxPreference and if ti's true we'll overlay the image onto our Activity/Fragment:
setNoti = PreferenceManager.getDefaultSharedPreferences(this);
// SharedPref tutorial
showTut = setNoti.getBoolean("tutorial", true);
if (showTut == true) {
showActivityOverlay();
}
Now for the last part we'll create the method to display the overlay. We will create a Dialog and apply a translucent theme with no title bar, this provides a dialog that covers our activity but doesn't hide our notification bar.
private void showActivityOverlay() {
final Dialog dialog = new Dialog(this,
android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.overlay_activity);
LinearLayout layout = (LinearLayout) dialog
.findViewById(R.id.llOverlay_activity);
layout.setBackgroundColor(Color.TRANSPARENT);
layout.setOnClickListener(new OnClickListener() {
@override
public void onClick(View arg0) {
dialog.dismiss();
}
});
dialog.show();
}
We'll use a method like this whereever we want to display the overlay to our users. When we get to the last overlay it is best to change the value in our SharedPreferences so we don't continue showing the overlays to the user. We do that with this variation on our above method where in the onClick we update the SharePreferences to set our tutorial to false.
private void showActivityOverlay() {
final Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.overlay_activity);
LinearLayout layout = (LinearLayout) dialog
.findViewById(R.id.llOverlay_activity);
layout.setBackgroundColor(Color.TRANSPARENT);
layout.setOnClickListener(new OnClickListener() {
@override
public void onClick(View arg0) {
// Get SharedPrefs
PreferenceManager.setDefaultValues(getActivity(), R.xml.prefs, true);
SharedPreferences setNoti = PreferenceManager
.getDefaultSharedPreferences(getActivity());
setNoti.edit().putBoolean("tutorial", false).commit();
showTut = false;
dialog.dismiss();
}
});
dialog.show();
}
And there you have it! As I mentioned at the begging of this post, this can be applied to an Activity or a Fragment. You'll notice in the last method instead of using the context of "this" I'm using the context of "getActivity()", that is the only change you have to make for this to work with a Fragment.
I am publishing the full code on my GitHub. Please feel free to leave comments, questions or your own pointers below.
https://github.com/marty331/overlaytutorial
Thanks for reading!
Cool guide.
I suggest adding [GUIDE] or [HOW-TO] to the thread title to make it easier to find. I thought it was a question when I clicked on it.
marty331 said:
I recommend you draw them 480 X 760 px.
[...]
overlay_activity.xml
Code:
[/QUOTE]
Where's your code? :(
Personally, I'd use Inkscape to create them as a *.svg and convert them to a *.png file later. That way they will not look pixelated.
Click to expand...
Click to collapse
nikwen said:
Where's your code?
Personally, I'd use Inkscape to create them as a *.svg and convert them to a *.png file later. That way they will not look pixelated.
Click to expand...
Click to collapse
Somehow my post was corrupted, I edited it and re-pasted everything.
I haven't tried Inkscape, but am up for giving that a go.
marty331 said:
Somehow my post was corrupted, I edited it and re-pasted everything.
I haven't tried Inkscape, but am up for giving that a go.
Click to expand...
Click to collapse
Great. Thank you.
The only thing which would be even better now would be using
Code:
tags. ;)
I didn't do much with it. However, scaling SVGs looks much better because they consist of single lines and shapes which can be rendered for all densities.
The disadvantage is that it is more difficult to create good-looking graphic effects in SVG.
I just found the Showcaseview library. It looks very promising.
Homepage: http://espiandev.github.io/ShowcaseView/
Github code: https://github.com/Espiandev/ShowcaseView
nikwen said:
I just found the Showcaseview library. It looks very promising.
Homepage: http://espiandev.github.io/ShowcaseView/
Github code: https://github.com/Espiandev/ShowcaseView
Click to expand...
Click to collapse
nikwen,
ShowcaseView is really awesome, I agree. However, it does not work with Fragments yet. Super bummer!
marty331 said:
nikwen,
ShowcaseView is really awesome, I agree. However, it does not work with Fragments yet. Super bummer!
Click to expand...
Click to collapse
Why do you think so?
Shouldn't this work? Correct me if I am wrong.
Code:
ShowcaseView.ConfigOptions co = new ShowcaseView.ConfigOptions();
co.hideOnClickOutside = true;
sv = ShowcaseView.insertShowcaseView(R.id.buttonBlocked, getActivity(), R.string.showcase_main_title, R.string.showcase_main_message, co);
(Code based on this: https://github.com/Espiandev/Showca...andev/showcaseview/sample/SampleActivity.java)
I agree that it should, however it does not. I've emailed the developer and he said he will work on it. If you want to use ShowcaseView in an activity it works very well.
marty331 said:
I agree that it should, however it does not. I've emailed the developer and he said he will work on it. If you want to use ShowcaseView in an activity it works very well.
Click to expand...
Click to collapse
Ok, that's strange.
Thanks exactly what I was looking for!
Sent from my Galaxy Nexus using Tapatalk 4 Beta
marty331 said:
I agree that it should, however it does not. I've emailed the developer and he said he will work on it. If you want to use ShowcaseView in an activity it works very well.
Click to expand...
Click to collapse
I got it to work.
I will push my code to Github later, but I will improve it before.
Then I will write a tutorial for that.
Here is my pull request: https://github.com/Espiandev/ShowcaseView/pull/68
Guide for doing it using the ShowcaseView library: http://forum.xda-developers.com/showthread.php?t=2419939
This guide is great. Thanks again. Please understand that by posting this I don't want to criticise, offend or denigrate you.
You got mentioned in my guide.
marty331 said:
Somehow my post was corrupted, I edited it and re-pasted everything.
I haven't tried Inkscape, but am up for giving that a go.
Click to expand...
Click to collapse
I think you should also disable smiles in the OP!
androidrientation=„blahblahblah” is android(smile)rientation!
great tut.
thanks
cascio97 said:
I think you should also disable smiles in the OP!
androidrientation=„blahblahblah” is android(smile)rientation!
Click to expand...
Click to collapse
I always use another trick:
Code:
android:[B[I][/I]][/B[I][/I]]orientation
The result:
Code:
android:[B][/B]orientation
That allows you to use smileys in other parts of the post.
nikwen said:
I always use another trick:
Code:
android:[B[I][/I]][/B[I][/I]]orientation
The result:
Code:
android:[B][/B]orientation
That allows you to use smileys in other parts of the post.
Click to expand...
Click to collapse
Thank you! didn't know about this one!
Sent from my Galaxy Nexus using XDA Premium 4 mobile app

[Guide] Creating a Floating Window out of your App

This is a project that I whipped together to show developers how to implement a floating window type popup for their apps. An example usage would be quick reply to a sms message, email, or any other times quick reply would come in handy. It isn't limited to just that though, using this method, you will be able to completely recreate any activity in windowed form with very little code edits.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
My brother an I have used this to create a quick reply for our app, Sliding Messaging Pro. The idea is basically the exact same as Halo, with almost the exact same implementation. We do it by extending the MainActivity in a pop up class, then using an overrode setUpWindow() function to set up your MainActivity in the window.
The full source is availible on my GitHub, found here: Floating Window GitHub
Play Store Link: Floating Window Demo
So now to the actual steps to creating your own "floating window popup" out of your apps MainActivity:
1.) First, we should add the styles that we are going to use to the styles.xml sheet.
These are the styles for the animation, of course you can define your own animation if you choose, these will bring the window up from the bottom of the screen and the close it to the bottom of the screen.
Code:
<style name="PopupAnimation" parent="@android:style/Animation">
<item name="android:windowEnterAnimation">@anim/activity_slide_up</item>
<item name="android:windowExitAnimation">@anim/activity_slide_down</item>
</style>
Now, this style is for the actual popup dialog box. You can play with the different values here all you want. We end up overriding some of these when we set up the window anyways, such as the dimming.
Code:
<style name="Theme.FloatingWindow.Popup" parent="@android:style/Theme.Holo.Light" >
<item name="android:windowIsFloating">false</item>
<item name="android:windowSoftInputMode">stateUnchanged</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowAnimationStyle">@style/PopupAnimation</item>
<item name="android:windowCloseOnTouchOutside">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
2.) Now that your styles are set up, lets go ahead and add the new Popup activity to the manifest. You can see that we used the Theme.FloatingWindow.Popup style that we just defined in the last step. You will also have to add
Code:
xmlns:tools="http://schemas.android.com/tools"
to the xmlns declarations at the top of the manifest.
Code:
<activity
android:name="PopupMainActivity"
android:label="@string/app_name"
android:theme="@style/Theme.FloatingWindow.Popup"
android:configChanges="orientation|screenSize"
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
android:clearTaskOnLaunch="true"
android:exported="true"
tools:ignore="ExportedActivity" />
3.) One more thing that we have to put in before you have resolved all the errors here, the animations. Just copy and paste these two animations in separate files under the res/anim folder. Name one activity_slide_down.xml and the other activity_slide_up.xml
activity_slide_down.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="0%" android:toYDelta="100%"
android:duration="300"/>
</set>
activity_slide_up.xml
Code:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<translate android:fromXDelta="0%" android:toXDelta="0%"
android:fromYDelta="100%" android:toYDelta="0%"
android:duration="300"/>
</set>
4.) Now that everything should be set up, we will make the actual popup activity! You can view my full code for this from the GitHub link, but basically, we are going to make a PopupMainActivity.java class and extend the MainActivity class. If you understand inheritance at all with java, you will know what this is doing. It is going to allow this PopupMainActivity class, when started, to override methods from the MainActivity to produce different outcomes.
The method that actually makes the windowed pop up I have named setUpWindow(). This means that whenever this activity is called instead of the main activity, it will use this method instead of the main activities setUpWindow() method. This is very convieniet since we don't want to do any extra work than we need to in this class. So here is the code for that class:
Code:
/**
* This method overrides the MainActivity method to set up the actual window for the popup.
* This is really the only method needed to turn the app into popup form. Any other methods would change the behavior of the UI.
* Call this method at the beginning of the main activity.
* You can't call setContentView(...) before calling the window service because it will throw an error every time.
*/
@Override
public void setUpWindow() {
// Creates the layout for the window and the look of it
requestWindowFeature(Window.FEATURE_ACTION_BAR);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,
WindowManager.LayoutParams.FLAG_DIM_BEHIND);
// Params for the window.
// You can easily set the alpha and the dim behind the window from here
WindowManager.LayoutParams params = getWindow().getAttributes();
params.alpha = 1.0f; // lower than one makes it more transparent
params.dimAmount = 0f; // set it higher if you want to dim behind the window
getWindow().setAttributes(params);
// Gets the display size so that you can set the window to a percent of that
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
// You could also easily used an integer value from the shared preferences to set the percent
if (height > width) {
getWindow().setLayout((int) (width * .9), (int) (height * .7));
} else {
getWindow().setLayout((int) (width * .7), (int) (height * .8));
}
}
You can see what it does from the comments, but basically, it just initializes your main activity in a windowed for, exactly what we are trying to do!
5.) Now to actually have this method override something in the MainActivity, you must add the same method there. In my example, The method is just blank and has no implementation because i don't want it to do anything extra for the full app. So add this activity and the error that "your method doesn't override anything in the super class" will go away. Then you actually have to call this method from your MainActivity's onCreate() method so that it will set up the windowed app when it is suppose to.
Code:
/**
* Called when the activity is first created to set up all of the features.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
// If the user is in the PopupMainActivity function, the setUpWindow function would be called from that class
// otherwise it would call the function from this class that has no implementation.
setUpWindow();
// Make sure to set your content view AFTER you have set up the window or it will crash.
setContentView(R.layout.main);
// Again, this will call either the function from this class or the PopupMainActivity one,
// depending on where the user is
setUpButton();
}
As you can see from the code, I called this method before i set the content view for the activity. This is very important, otherwise you will get a runtime exception and the app will crash every time.
After you are done with that, you have successfully set up a program that will change from a windowed state to a full app state depending on which class is called. For example, if you set up an intent to open the floating window app, it would look something like this:
Code:
Intent window = new Intent(context, com.klinker.android.floating_window.PopupMainActivity.class);
window.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(window);
You are still able to call the MainActivity class like you normally would then. with an intent like this:
Code:
Intent fullApp = new Intent(context, MainActivity.class);
fullApp.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(fullApp);
That is just about it, obviously my solution and demo are very simple implementations of what it can do. You can see from the demo app that I simply go back and forth between the activities with a button, then i have an edittext at the bottom to demonstrate how the window resizes.
You can literally do anything with this though. It will work with any layouts you have set up and is a very cool way for your users to experience your app in a different light. If you want to change how something works in the popup part of the app, all you have to do is function that portion of code out, then override that method from the popup activity, so the possibilities are endless with what can be done here.
Credit for this goes to the Paranoid Android team of course for inspiring the idea, then Jacob Klinker (klinkdawg) and myself (Luke Klinker) for the implementation without framework tweaks or custom roms. This should work for any users, no matter the phone, android version, or custom rom.
I honestly have no clue if it will work on anything below 4.0, but if you test and find out, sound off in the comments!
Thanks and enjoy! I hope to see lots of dynamic and awesome popups in the future because it really is just that simple, it won't take you more than a half hour to get this working!
I love your Sliding Messaging app. Really awesome work. The BEST messaging app out there. I'm in the beta group. Thank you for this information!
Sent from my XT875 using Tapatalk
I assume that this tutorial works with gingerbread..?
aniket.lamba said:
I assume that this tutorial works with gingerbread..?
Click to expand...
Click to collapse
It says at the bottom of the article that I don't know if it will work on anything below ICS. It relies on a dialog theme, which obviously existed pre ICS, but I have no way of checking if it works the same or not. Try it and let me know I guess!
Thank you for your sharing.
I used your example to add this amazing feature into Telepatch, an Open Source project, fork of Telegram
Thanks again!
[Idea] Create FloatingActivity type
This is an extremely awesome project, easy to implement, and very light weight, however, the only problem is that when i call the floating activity for example from a notification or whatever, the background activity closes, and i haven't been able to get around it
However, just an idea, which is what i did, create a separate Activity and put the setUpWindow() method in it, and override the onCreate() method and setUpWindow() in it, and after that, you can just create any activity and extends the FloatingActivity class and you're done, just make sure that you call super.onCreate() if you (probably) overrided the onCreate() method:laugh:
Hi, I've tried your solution. It works perfectly!
But when we touch homescreen button, the app is minimized. How can we make it persistent?
How to make truecaller like floating window..for incoming calls

Header for every layout

Hey guys this is the image which I would like to set at the top of every layout below the action bar...I dont want to include and set it in each and every layout.
So any alternatives for the same. I want this image to be displayed in all oof my application.
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
coolbud012 said:
Hey guys this is the image which I would like to set at the top of every layout below the action bar...I dont want to include and set it in each and every layout.
So any alternatives for the same. I want this image to be displayed in all oof my application.
Click to expand...
Click to collapse
If it is just one view, you can do it similar to the dividers in the third answer to this question. Have a style for the list heading (probably referencing the system or support library resources, depending on the lowest API you use) and then just add the small view wherever you want it. There is also another way using the <include> tag, so you can use a separate xml file to declare your header layout.
SimplicityApks said:
If it is just one view, you can do it similar to the dividers in the third answer to this question. Have a style for the list heading (probably referencing the system or support library resources, depending on the lowest API you use) and then just add the small view wherever you want it. There is also another way using the <include> tag, so you can use a separate xml file to declare your header layout.
Click to expand...
Click to collapse
I dont want to go with include even that way I would have to put the include in every layout.
Should I go with and put this into BaseActivity.java so that it would be loaded with each activity.
Code:
View view = new View(this);
view.setLayoutParams(new LayoutParams(2,LayoutParams.FILL_PARENT));
view.setBackgroundColor(Color.BLACK);
layout.add(view);
Or should I go with this only :
Code:
<style name="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">?android:attr/listDivider</item>
</style>
Then in my layouts is less code and simpler to read.
<View style="@style/Divider"/>
But the main issues with using the style is that I am using 1 style for layouts in which I am repeating the layout...and I cant use 2 styles for 1 ViewGroup...
I want to know the most optimized way...
coolbud012 said:
I dont want to go with include even that way I would have to put the include in every layout.
Should I go with and put this into BaseActivity.java so that it would be loaded with each activity.
Code:
View view = new View(this);
view.setLayoutParams(new LayoutParams(2,LayoutParams.FILL_PARENT));
view.setBackgroundColor(Color.BLACK);
layout.add(view);
Or should I go with this only :
Code:
<style name="Divider">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">1dp</item>
<item name="android:background">?android:attr/listDivider</item>
</style>
Then in my layouts is less code and simpler to read.
<View style="@style/Divider"/>
But the main issues with using the style is that I am using 1 style for layouts in which I am repeating the layout...and I cant use 2 styles for 1 ViewGroup...
I want to know the most optimized way...
Click to expand...
Click to collapse
Well I don't think there is an easy way to get around putting one line in every layout. So I assume that you want to use a single ImageView to show the image, so create a
Code:
<style name="header">
<item name="android:scr">@drawable/yourimage</item>
<!-- additional information like scale Type and such -->
</style>
And then in each layout, just add
<ImageView style="header"/>
Wherever you need it. I think that's the simplest way to do it.
SimplicityApks said:
Well I don't think there is an easy way to get around putting one line in every layout. So I assume that you want to use a single ImageView to show the image, so create a
Code:
<style name="header">
<item name="android:scr">@drawable/yourimage</item>
<!-- additional information like scale Type and such -->
</style>
And then in each layout, just add
<ImageView style="header"/>
Wherever you need it. I think that's the simplest way to do it.
Click to expand...
Click to collapse
Ok thanks for the suggestion...what about the first way I have described above?
else will follow what you have instructed...
coolbud012 said:
Ok thanks for the suggestion...what about the first way I have described above?
else will follow what you have instructed...
Click to expand...
Click to collapse
Ah you're right, you could also do it programmatically. Not sure what the best way would be, but you could create an abstract class HeaderActivity that would contain the code in the onCreate() so all your activities could extend that class instead of Activity or FragmentActivity. You would need to have one ID for all your top level layout, to call findViewById(R.id.top_view).addView(imageView, 0);
In the HeaderActivity. And you could also set your layout directly in its onCreate with an abstract method getLayoutId.
SimplicityApks said:
Ah you're right, you could also do it programmatically. Not sure what the best way would be, but you could create an abstract class HeaderActivity that would contain the code in the onCreate() so all your activities could extend that class instead of Activity or FragmentActivity. You would need to have one ID for all your top level layout, to call findViewById(R.id.top_view).addView(imageView, 0);
In the HeaderActivity. And you could also set your layout directly in its onCreate with an abstract method getLayoutId.
Click to expand...
Click to collapse
seems to be a great idea but...I had dropped out the idea of header and instead simplified the app header a bit...
Have a look at https://play.google.com/store/apps/details?id=com.droidacid.apticalc
U can create one Base Activity which extends "FragmentActivity" or "SherlockFragmentActivity"(if u use it) and then put that header on the top...below it create a fragment and in the whole app just replace that fragment and stay in one activity only..then u just need to have only one layout for the header and you can do the rest very easily....

[Tutorial] Programming for Sony Products [SmartEyeGlass][SourceCode]

Programming for Wearable Products of Sony (SmartEye-Glass)
The newest wearable project of Sony is the SmartEye-Glass. As we know Sony was one of the first company that seriously worked on smart wearable tech, actually Smart-Watch word is for Sony from the first generation of Smart-Watch.
Because There is lots of & Tutorial for SmartWatch I decided to start with SmartEye-Glass. However this is still preview of this SDK & I will update this tutorial as soon as final sdk release.
Imagine that you walk into an airport and instantly get directions to your check-in desk, or that you get scores and names of players displayed while watching a football game in real life. These are just some of the potential use cases of the new SmartEyeglass concept from Sony... read more
Click to expand...
Click to collapse
### Let Start ###
To use this tutorial & test the apps
you don't need to know anything
But if you interest to work more
you should know at least basic of Android/Java Programming
Click to expand...
Click to collapse
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
1. Install SmartEyeGlass SDK (Preview)
* Android SDK Manager:
- Open SDK-Manager go to > Tools > Manager Add-on Sites > User Defined (tab) > New > Add this URL
HTML:
http://dl.developer.sony.com/wearables/sdks/Sony-SmartEyeglass-SDK.xml
- Close & Relaunch the SDK-Manager
- In API-18 section you should have Sony
HTML:
SmartEyeGlass SDK Developer Preview
- Select & Install
* Manually:
- I attached the Compiled Library of SmartEyeGlass.
Download, unzip & Import to your WorkSpace
- To Develop Or Compile Sample code you should Add this library to your project
Code:
Right Click on Project > Properties > Android > in Library section > Add & Select All three package.[/CODE
[CENTER]***
[B]Ready To Coding for SmartEyeGlass[/B]
[B]^-^-^[/B]
[LEFT][SIZE=5][COLOR=DimGray]2. [B]Starting...
[/B][/COLOR][/SIZE]As Sony recommends, It s better to [B]Import Samples & Modify [/B]It. But will explain little bit about each part.
[FONT=Century Gothic][SIZE=4][FONT=Comic Sans MS]
#First For those who just want to test[/FONT][/SIZE][/FONT][B][FONT=Century Gothic][SIZE=4]
[/SIZE][/FONT][/B][FONT=Century Gothic][SIZE=3][FONT=Comic Sans MS]1. Download & Install [URL="http://forum.xda-developers.com/attachment.php?attachmentid=2957949&stc=1&d=1412279989"][COLOR=DeepSkyBlue][B]SmartEyeglassEmulator.apk[/B][/COLOR][/URL] + [/FONT][/SIZE][/FONT][FONT=Century Gothic][SIZE=3][FONT=Comic Sans MS][URL="http://forum.xda-developers.com/attachment.php?attachmentid=2957948&stc=1&d=1412279989"][COLOR=DeepSkyBlue][B][FONT=Century Gothic][FONT=Comic Sans MS]SmartEyeglass.apk[/FONT][/FONT][/B][/COLOR][/URL]
2. Then Install One of the Application from [URL="http://forum.xda-developers.com/attachment.php?attachmentid=2957870&stc=1&d=1412275816"][COLOR=DeepSkyBlue][B]samplesAPK.rar [/B][/COLOR][/URL]
3. Now Open the [/FONT][/SIZE][/FONT][FONT=Century Gothic][SIZE=3][FONT=Comic Sans MS][FONT=Century Gothic][FONT=Comic Sans MS][B]SmartEyeglassEmulator[/B][/FONT][/FONT] app
4. [B]Swipe Left/Right[/B] on [COLOR=SeaGreen][B]green[/B] [/COLOR]area to find Installed App & Click on [B]Touch Sensor[/B] button to Select.
5. For Example, Select Sample Voice Text Input + Turn ON [B]PTT [/B]switch & Speak [SIZE=2](Internet Connection Required)[/SIZE]
6. That s it... Just Install other App & play with them ;)
check out the SceenShot;[/FONT][/SIZE][/FONT][B][FONT=Century Gothic][SIZE=4]
[/SIZE][/FONT][/B][CENTER][HIDE][IMG]http://forum.xda-developers.com/attachment.php?attachmentid=2957871&stc=1&d=1412275818[/IMG][/HIDE]
[/CENTER]
[B][FONT=Century Gothic][SIZE=4]
# SampleVoiceTextInput [/SIZE][/FONT][/B][FONT=Lucida Console][SIZE=2]Codes Descriptions[/SIZE][/FONT][B]
I.[/B] First you should add required [B]permissions[/B] in [B]Manifest.xml[/B].
[CODE] <uses-permission android:name="com.sonyericsson.extras.liveware.aef.EXTENSION_PERMISSION" />
<uses-permission android:name="com.sony.smarteyeglass.permission.SMARTEYEGLASS" />
<!-- This is permission of Text Input functionality as i used for first Sample. you should modify it based on which API want to use -->
<uses-permission android:name="com.sony.smarteyeglass.permission.VOICE_TEXT_INPUT" />
II. Define BroadCast-Receiver to Handle Each Intent-Filter Actions & Invoke the Service.
Code:
<receiver android:name="com.example.sony.smarteyeglass.extension.samplevoicetextinput.ExtensionReceiver" >
<intent-filter>
<!-- Generic extension intents. -->
<action android:name="com.sonyericsson.extras.liveware.aef.registration.EXTENSION_REGISTER_REQUEST"/>
<action android:name="com.sonyericsson.extras.liveware.aef.registration.ACCESSORY_CONNECTION" />
<action android:name="android.intent.action.LOCALE_CHANGED" />
<!-- Notification intents -->
<action android:name="com.sonyericsson.extras.liveware.aef.notification.VIEW_EVENT_DETAIL" />
<action android:name="com.sonyericsson.extras.liveware.aef.notification.REFRESH_REQUEST" />
<!-- Widget intents -->
<action android:name="com.sonyericsson.extras.aef.widget.START_REFRESH_IMAGE_REQUEST" />
<action android:name="com.sonyericsson.extras.aef.widget.STOP_REFRESH_IMAGE_REQUEST" />
<action android:name="com.sonyericsson.extras.aef.widget.ONTOUCH" />
<action android:name="com.sonyericsson.extras.liveware.extension.util.widget.scheduled.refresh" />
<!-- Control intents -->
<action android:name="com.sonyericsson.extras.aef.control.START" />
<action android:name="com.sonyericsson.extras.aef.control.STOP" />
<action android:name="com.sonyericsson.extras.aef.control.PAUSE" />
<action android:name="com.sonyericsson.extras.aef.control.RESUME" />
<action android:name="com.sonyericsson.extras.aef.control.ERROR" />
<action android:name="com.sonyericsson.extras.aef.control.KEY_EVENT" />
<action android:name="com.sonyericsson.extras.aef.control.TOUCH_EVENT" />
<action android:name="com.sonyericsson.extras.aef.control.SWIPE_EVENT" />
</intent-filter>
</receiver>
III. Now Need a Class extended of ExtensionService
Code:
<service android:name="com.example.sony.smarteyeglass.extension.samplevoicetextinput.SampleExtensionService" />
Save the Manifest And let check each classes.
IV. As you know the first thing class is BroadcastReceiver
This Class Receive the Broadcast message and invoke the a Service to Handle Other events.
Code:
@Override
public void onReceive(final Context context, final Intent intent) {
intent.setClass(context, SampleExtensionService.class);
context.startService(intent);
}
V. ExtensionService class.
Sony Dev:
* The Extension Service handles registration and keeps track of all
* extension class on all accessories.
Click to expand...
Click to collapse
The Registration is invoke the API Handler class extended from RegistrationInformation that Check required info & configuration.
from Display Info to API Info
for this Sample SampleRegistrationInformation extends RegistrationInformation to identify extension you should check;
Code:
/** Uses control API version*/
private static final int CONTROL_API_VERSION = 4;
@Override
public int getRequiredControlApiVersion() {
return [B]CONTROL_API_VERSION[/B];
}
So cause this is not Notification Or Sensor Based API that used in this sample you will have this
Code:
@Override
public int getRequiredSensorApiVersion() {
return RegistrationInformation.[B]API_NOT_REQUIRED[/B];
}
@Override
public int getRequiredNotificationApiVersion() {
return RegistrationInformation.[B]API_NOT_REQUIRED[/B];
}
* IF you want to use Notification API you should define it like this
Code:
@Override
public int getRequiredNotificationApiVersion() {
// Notification API level
return [B]1[/B];
}
Finally in this class you should invoke the Controller Class. (control extension handles a control on an accessory.)
Code:
@Override
public ControlExtension createControlExtension(final String hostAppPackageName) {
return new SampleVoiceTextInputControl(this, hostAppPackageName);
}
VI. ControlExtension class
It s similar to Other Controller class that actually known as Event Handler/Listener.
- First define parameter to get instance of utility & hardware side
/** Instance of the Control Utility class. */
//The control extension handles a control on an accessory
Code:
private final [B]SmartEyeglassControlUtils[/B] utils;
to get instance of microphone & return the results.
listener for the SmartEyeglass device, and define a callback handler method for the onVoiceTextInput event. The completed voice-input operation sends this event with the text and an error code (0 on success)...
Click to expand...
Click to collapse
- After this it s time to create Listener & get Result;
Code:
final SmartEyeglassEventListener listener = new SmartEyeglassEventListener(){
@Override
public void onDialogClosed(final int code) {
Log.d(Constants.LOG_TAG, "onDialogClosed() : " + code);
}
@Override
public void onVoiceTextInput(final int errorcode, final String text) {
String message;
if (errorcode == 0) { //errorcode == 0 means Successful operation.
[COLOR=Red][B] // And Here
//You get the test Result & can add an operation you like.
//simple Toast notification or invoking another class & ...[/B][/COLOR]
message = "Inputted text : " + text;
Toast.makeText(c, text, Toast.LENGTH_SHORT).show();
}
else {
message = "Text Input Canceled";
Toast.makeText(c, message, Toast.LENGTH_SHORT).show();
}
utils.showDialogMessage(message, SmartEyeglassControl.Intents.DIALOG_MODE_OK);
}
};
utils = new SmartEyeglassControlUtils(hostAppPackageName, listener);
utils.activate(context);
- At the end you must deactive System Utils to allow other extension or apps use it.
Code:
@Override
public void onDestroy() {
utils.deactivate();
};
VII. This sample finished. + By Checking each class you will get more things to understand.
So Open Sample Code & Check it carefully.
API Reference is Best Place to Find All Functions & Technical Description... Read More
Click to expand...
Click to collapse
3. Test App
1. Download & Install SmartEyeglassEmulator.apk + SmartEyeglass.apk from Attachments
2. Open the SmartEyeglassEmulator app
3. Swipe Left/Right on green area to find Installed App & Click on Touch Sensor button to Select.
OOOOOOO ​
The explanations of codes are available inside each classes.
​
If you find any mistake Or issue in my codes Please inform me.
Click to expand...
Click to collapse
Tutorial & Sample Codes for
- SmartWatches (Android-Wear)
Coming Soon...
​
Don't forget to Hit Thanks​​[/LEFT]
[/CENTER]
Reserved
...
Super Tutorial Bro.. If i was not in office i would have tried it right away. THANKS A LOT.
And I feel this should be read and placed along with the Portal News post abt Smart Eye wear SDK.
You have created such a nice tutorial for all the developers.
Info
aniketh12 said:
Super Tutorial Bro.. If i was not in office i would have tried it right away. THANKS A LOT.
And I feel this should be read and placed along with the Portal News post abt Smart Eye wear SDK.
You have created such a nice tutorial for all the developers.
Click to expand...
Click to collapse
Thanks
maybe if you and others send request to XDA they will feature it
:good:
i like these glasses
But the price is overwhelming
great thread i have always wanted one but yet i can not afford it at the time
My SEG working fine thanks to this thread
Info
dinhantauwater said:
My SEG working fine thanks to this thread
Click to expand...
Click to collapse
Thanks for Review
Please Send your Project Link & Description
:good:
I have installed all the apps etc according to this forum and the sony developer website but I do not see any green text in the emulator app. All I see is the black background with all other buttons etc as expected. When I swipe there is also no green text/cards?
Do I need my phone connected to the glasses because I think this would defeat the purpose of having an emulator app.
I look forward to hearing from someone soon
update:
I managed to get it working after a restart, but now if I setup a AVD in Android Studio, is there a way of getting the SmartEyeglass Emulator working? At the moment it is showing the app opened but no green display on the black background?
Info
stealthdragonb said:
I have installed all the apps etc according to this forum and the sony developer website but I do not see any green text in the emulator app. All I see is the black background with all other buttons etc as expected. When I swipe there is also no green text/cards?
Do I need my phone connected to the glasses because I think this would defeat the purpose of having an emulator app.
I look forward to hearing from someone soon
update:
I managed to get it working after a restart, but now if I setup a AVD in Android Studio, is there a way of getting the SmartEyeglass Emulator working? At the moment it is showing the app opened but no green display on the black background?
Click to expand...
Click to collapse
When you Swipe you should see list of Available App IF Emulator App can detect them.
Code:
3. Swipe Left/Right on green area to find Installed App & Click on Touch Sensor button to Select.
It won't work properly If you install emulator app on AVD.
:good:
Geeks Empire said:
When you Swipe you should see list of Available App IF Emulator App can detect them.
Code:
3. Swipe Left/Right on green area to find Installed App & Click on Touch Sensor button to Select.
It won't work properly If you install emulator app on AVD.
:good:
Click to expand...
Click to collapse
That was the first thing I tried. swiping does not bring up any display/cards onto the screen in the AVD emulator in Android Studio, but works on my actual android device running the eyeglass emulator.
Any other suggestions? Also I am completely new to java, any useful tutorials etc you can refer me to. The one on Sony's Eyeglass developer website tutorials seems to advanced for me at this stage
Info
stealthdragonb said:
That was the first thing I tried. swiping does not bring up any display/cards onto the screen in the AVD emulator in Android Studio, but works on my actual android device running the eyeglass emulator.
Any other suggestions? Also I am completely new to java, any useful tutorials etc you can refer me to. The one on Sony's Eyeglass developer website tutorials seems to advanced for me at this stage
Click to expand...
Click to collapse
Yes. It s better to use Actual Android Device & then Install Emulator APK.
Just Search Java Tutorial
I recommend you to Read Xperia Small App Tutorial. Cause It includes basic of Android Programming.
http://forum.xda-developers.com/cro...ramming-xperia-smallapp-sample-codes-t2888848
:good:
Thanks very much for your help, I appreciate it.
One last question is do you know if I can use a secondary mic input, such as a Bluetooth mic connected to my android device and use it for voice commands for the eyeglass? Ideally I do not want to use the mic located in the touch device connected to the eyeglass.
Hi,
I have gone through the basics of writing java and modifying xml files etc for a normal phone app. I have gone through basic examples such as hello world right through to speech to text and calculator apps.
The issue I am having now is how do I for example write a simple hello world application from scratch for the sony smart glasses. The sample sdk files given on the sony website is quite difficult for me to understand as there are little to no tutorials available and everything I have learnt thus far is for just an android phone interface.
The main issue will be with a phone app, I can simply tap on boxes etc and make a selection. e.g. how do I use the top and scroll functions on the smart eyeglass controller and which part of the code I should use for this?
I'll really appreciate some advice from people. Thanks in advance!
Info
stealthdragonb said:
Hi,
I have gone through the basics of writing java and modifying xml files etc for a normal phone app. I have gone through basic examples such as hello world right through to speech to text and calculator apps.
The issue I am having now is how do I for example write a simple hello world application from scratch for the sony smart glasses. The sample sdk files given on the sony website is quite difficult for me to understand as there are little to no tutorials available and everything I have learnt thus far is for just an android phone interface.
The main issue will be with a phone app, I can simply tap on boxes etc and make a selection. e.g. how do I use the top and scroll functions on the smart eyeglass controller and which part of the code I should use for this?
I'll really appreciate some advice from people. Thanks in advance!
Click to expand...
Click to collapse
I mentioned
But if you interest to work more
you should know at least basic of Android/Java Programming
Click to expand...
Click to collapse
Read Tutorial Again Carefully.
It is just Simple Hello Wolrd! of Android with Modifications.
& I explained each modifications.
So Create a Project and Add these Codes.
NOTE: You have to use Samples Because of Limited Available API. So Whatever you use sample codes OR manually add codes, you will get same result.
I will check If there New API and Documentation I will Add Descriptions & New Sample
:good:

[Tutorial] Implement a Navigation Drawer with a Toolbar on Android

Hello,
I create that thread to share with you a tutorial showing you how to implement a Navigation Drawer with a Toolbar on Android. You can find the tutorial here on my blog : http://www.ssaurel.com/blog/implement-a-navigation-drawer-with-a-toolbar-on-android-m/ . There are also others great tutorials for Android development.
If you prefer to read the tutorial here, this is the complete content :
Implement a Navigation Drawer with a Toolbar on Android
Navigation drawer is a great UI pattern recommended by Google when you design your Android application. Introduced with Android Lollipop, the Toolbar widget is a flexible way to customize easily the action bar. In this tutorial, you’re going to learn how to implement a navigation drawer with a toolbar on Android M.
1. Get Material Colors
First, you need to get material colors for your application. A website like http://www.materialpalette.com can be useful to create quickly your material colors file. Here, we choose green and light green as primary colors :
Code:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#4CAF50</color>
<color name="primary_dark">#388E3C</color>
<color name="primary_light">#C8E6C9</color>
<color name="accent">#8BC34A</color>
<color name="primary_text">#212121</color>
<color name="secondary_text">#727272</color>
<color name="icons">#FFFFFF</color>
<color name="divider">#B6B6B6</color>
</resources>
Put your XML resource file, got from Material Palette, in the folder res/values of your Android project.
2. Configure your dependencies
Now, it’s time to configure dependencies in your build.gradle file. You need to import the following libraries :
Code:
com.android.support:appcompat-v7:23.3.0
com.android.support:design:23.3.0
3. Create a No Action Bar theme
To use the Toolbar widget, you need to create a No Action Bar theme for your activity. In your styles.xml file under res/values, you can create the following theme :
Code:
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
</style>
<style name="MyAppTheme" parent="@style/AppTheme" />
</resources>
To enable some specific properties available from API V21, you need to create a folder named values-v21 and override the MyAppTheme like that :
Code:
<resources>
<style name="MyAppTheme" parent="AppTheme">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>
</resources>
Finally, you need to apply the MyAppTheme to a specific Activity with a Toolbar widget or if you want to your entire application :
Code:
<application
android:theme="@style/MyAppTheme" >
...
</application>
4. Create layout for the Toolbar
The Toolbar widget has been created to play the role that was dedicated to Action Bar previously. It can be used to hold :
Action menu
App title and subtitle
Navigation button(s)
Like the Toolbar will be used between several activities’ layouts, we create a separate layout file and apply our specific configuration with colors for example :
Code:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
Now, we could include the Toolbar in each activity and have just one place to change its configuration.
5. Add the Navigation Drawer to the Activity
Navigation Drawer is a great UI pattern recommended by Google when you develop Android applications. It’s a great way to organise navigation inside an application. Implementation is easy and we need to use DrawerLayout widget to implement it.
The layout of our main Activity will be like that :
Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar" />
<!-- For fragments -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/frame"/>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/nav_items" />
</android.support.v4.widget.DrawerLayout>
Here, you can note that we include the Toolbar widget defined at the step 4.
6. Create a navigation items menu
To define the content of the navigation drawer, we can define a navigation items menu in res/menu :
Code:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<group android:checkableBehavior="single">
<item android:id="@+id/refresh"
android:title="@string/refresh"
android:icon="@drawable/ic_action_refresh" />
<item android:id="@+id/stop"
android:title="@string/stop"
android:icon="@drawable/ic_action_stop" />
</group>
</menu>
Here, we define juste two entries in the menu.
7. Configure Toolbar and Navigation Drawer in Activity
All the resources file are ready. So, it’s time to configure Toolbar and Navigation Drawer in the Activity. It’s easy and we use dedicated method named configureToolbar and configureNavigationDrawer :
Code:
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
private RelativeLayout layout;
private DrawerLayout drawerLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
layout = (RelativeLayout) findViewById(R.id.layout);
configureNavigationDrawer();
configureToolbar();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.empty_menu, menu);
return true;
}
private void configureToolbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar actionbar = getSupportActionBar();
actionbar.setHomeAsUpIndicator(R.drawable.ic_action_menu_white);
actionbar.setDisplayHomeAsUpEnabled(true);
}
private void configureNavigationDrawer() {
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
NavigationView navView = (NavigationView) findViewById(R.id.navigation);
navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
Fragment f = null;
int itemId = menuItem.getItemId();
if (itemId == R.id.refresh) {
f = new RefreshFragment();
} else if (itemId == R.id.stop) {
f = new StopFragment();
}
if (f != null) {
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.frame, f);
transaction.commit();
drawerLayout.closeDrawers();
return true;
}
return false;
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
switch(itemId) {
// Android home
case android.R.id.home:
drawerLayout.openDrawer(GravityCompat.START);
return true;
// manage other entries if you have it ...
}
return true;
}
}
As you can see, it’s really simple to assemble all the pieces of the puzzle to have a functional application with a Navigation Drawer and a Toolbar.
If you have some questions about the content of fragments used here, it’s really simple. For example, this is the content of the RefreshFragment :
Code:
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment1 extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.refresh_fragment_layout, container, false);
return v;
}
}
After that, it’s your job to complete the fragment with your content.
8. Demo
Now, it’s time for demo of the application created. Some screenshots :
{
"lightbox_close": "Close",
"lightbox_next": "Next",
"lightbox_previous": "Previous",
"lightbox_error": "The requested content cannot be loaded. Please try again later.",
"lightbox_start_slideshow": "Start slideshow",
"lightbox_stop_slideshow": "Stop slideshow",
"lightbox_full_screen": "Full screen",
"lightbox_thumbnails": "Thumbnails",
"lightbox_download": "Download",
"lightbox_share": "Share",
"lightbox_zoom": "Zoom",
"lightbox_new_window": "New window",
"lightbox_toggle_sidebar": "Toggle sidebar"
}
9. Bonus
In bonus, you can follow this tutorial in a live coding video available in two parts on Youtube :
Don't hesitate to give it a try and give me your feedbacks.
I hope it can help you .
Sylvain
sylsau said:
Hello,
I create that thread to share with you a tutorial ...
...
Don't hesitate to give it a try and give me your feedbacks.
I hope it can help you .
Sylvain
Click to expand...
Click to collapse
Thanks for tutorial. Can you share the code? Thanks

Categories

Resources