I downloaded Launcher3 (Google's Kitkat Launcher) from 4.4 Sources.
I imported it into eclipse . I got rid of errors.And my launcher works pretty good.
But something missing. "GOOGLE NOW" page when you scroll to left.
I can't activate google now.Anyway i don't need that. I want to put my own fragment or layout into first page and other pages will work same like normal launcher.
Like a Google's experience Launcher(Kitkat Launcher of google)'s Google Now page ..
Like this :
I added my layout like this :
here is original codes from workspace.java
public long insertNewWorkspaceScreen(long screenId, int insertIndex) {
if (mWorkspaceScreens.containsKey(screenId)) {
throw new RuntimeException("Screen id " + screenId + " already exists!");
}
CellLayout newScreen = (CellLayout)
mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null);
newScreen.setOnLongClickListener(mLongClickListener);
newScreen.setOnClickListener(mLauncher);
newScreen.setSoundEffectsEnabled(false);
mWorkspaceScreens.put(screenId, newScreen);
mScreenOrder.add(insertIndex, screenId);
addView(newScreen, insertIndex);
return screenId;
}
here is edited codes by me on workspace.java
public long insertNewWorkspaceScreen(long screenId, int insertIndex) {
if (mWorkspaceScreens.containsKey(screenId)) {
throw new RuntimeException("Screen id " + screenId + " already exists!");
}
if (screenId == 2) //Firstscreen/page
{
RelativeLayout newScreen = (RelativeLayout)
mLauncher.getLayoutInflater().inflate(R.layout.blinkfeed, null);
newScreen.setOnClickListener(mLongClickListener);
newScreen.setOnClickListener(mLauncher);
newScreen.setSoundEffectsEnabled(false);
// mWorkspaceScreens.put(screenId, newScreen);
mScreenOrder.add(insertIndex, screenId);
addView(newScreen, insertIndex);
return screenId;
}
else
{
CellLayout newScreen = (CellLayout)
mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, null);
newScreen.setOnLongClickListener(mLongClickListener);
newScreen.setOnClickListener(mLauncher);
newScreen.setSoundEffectsEnabled(false);
mWorkspaceScreens.put(screenId, newScreen);
mScreenOrder.add(insertIndex, screenId);
addView(newScreen, insertIndex);
return screenId;
}
}
as you can see when its first page i changed layout but i'm getting problems on childviews, animations etc,
anyway i cant even access other pages after that.
i putted everywhere try catch when i get errors because of "celllayout cannot bind to relative bla bla .."
my try catch like this
try
{
cell layout stuff its trying to make animations etc.
}
catch (Exception e)
{
//empty
}
i couldn't make it work at the moment like a google now pages :)
does anybody know about adding a fragment/layout into first page ?
Thanks.
If you want to add some fragment or view in the same manner as Google Now, the Launcher3 code supports that. You basically have 2 ways of getting the desired behavior:
Subclass the Launcher class and overwrite hasCustomContentToLeft() to return true and addCustomContentToLeft() where you can create/inflate your view to be added. Make sure you call addToCustomContentPage and implement the CustomContentCallbacks if you want to be notified when the screen is open.
Implement the same methods as described above in the Launcher class directly.
Hope this helps,
Mihai
Related
I am developing an android blog app with Firebase Firestore. I want to show a Microsoft Office Word document in the app (because I want to add multiple styled texts).
When the user clicks on an article in the app, an activity will show the specified data. What I mean is that there will be different texts, so each article will have different content. What I want is to show styled text like the ones available in Microsoft Word (bullets and numbering, bold, italic... these stuff) in the content of the article.
I thought of uploading a word.docx document into the storage in Firebase and adding the link of it in the content field in Firestore. But I am sure that it will not work.
Does anyone know what should I do?
I have similar thing the only difference is I have shown pdf, but I am sure it can be done for doc also, you will need webView to make it work, I am providing you method that will open the file in webview by google docs, have a look:
private void setUpWebView() {
setWebviewSettings();
mwebView.clearHistory();
mwebView.clearFormData();
mwebView.clearCache(false);
mwebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
mwebView.setScrollbarFadingEnabled(true);
mwebView.getSettings().setSupportZoom(true);
mwebView.setWebChromeClient(new CustomWebChromeClient(this));
mwebView.setWebViewClient(new WebViewClient());
mwebView.getSettings().setJavaScriptEnabled(true);
mwebView.getSettings().setPluginState(WebSettings.PluginState.ON);
String url = AppConstants.FULL_TANDC_URL;
if (NetworkUtil.isNetworkAvailable(this)) {
if (url != null && !TextUtils.isEmpty(url) && URLUtil.isValidUrl(url)) {
textNoData.setVisibility(View.GONE);
if (url.contains(".pdf")) {
mwebView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + url);
mprogressBar.setVisibility(View.GONE);
} else {
mwebView.loadUrl(url);
mprogressBar.setVisibility(View.VISIBLE);
}
} else {
textNoData.setVisibility(View.VISIBLE);
mprogressBar.setVisibility(View.GONE);
}
} else {
mprogressBar.setVisibility(View.GONE);
textNoData.setVisibility(View.VISIBLE);
}
}
I hope this will help you.
Happy coding :)
Basically, what I am trying to do is change the CONTROL_AE_MODE by button click in the app. The user can use AUTO flash(ON_AUTO_FLASH), turn if ON(ON_ALWAYS_FLASH), or OFF(CONTROL_AE_MODE_OFF).
In this example: https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java
Line 818, they set the flash once:
// Use the same AE and AF modes as the preview.
captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,
CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
setAutoFlash(captureBuilder);
// Orientation
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, ORIENTATIONS.get(rotation));
CameraCaptureSession.CaptureCallback CaptureCallback
= new CameraCaptureSession.CaptureCallback() {
#Override
public void onCaptureCompleted(#NonNull CameraCaptureSession session,
#NonNull CaptureRequest request,
#NonNull TotalCaptureResult result) {
showToast("Saved: " + mFile);
Log.d(TAG, mFile.toString());
unlockFocus();
}
};
mCaptureSession.stopRepeating();
mCaptureSession.capture(captureBuilder.build(), CaptureCallback, null);
And then builds the CaptureSession at line 840.
Is there a way to change the CONTROL_AE_MODE after the preview is made?
I have tried remaking the session, which kinda worked:
if(flashMode == CameraView.CAMERA_FLASH_ON){
Log.e("CAMERA 2", "FLASH ON");
mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_ALWAYS_FLASH);
}else if(flashMode == CameraView.CAMERA_FLASH_OFF){
Log.e("CAMERA 2", "FLASH OFF");
mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_OFF);
}else if(flashMode == CameraView.CAMERA_FLASH_AUTO){
Log.e("CAMERA 2", "FLASH AUTO");
mPreviewCaptureRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
}
mFlashMode = flashMode;
if (mCameraCaptureSession != null) {
mCameraCaptureSession.close();
mCameraCaptureSession = null;
}
createCameraPreviewSession();
For some reason, CONTROL_AE_MODE_OFF would turn the whole preview black.
I tried looking in the docs for methods to update but haven't found anything.
Any tutorials or docs is much appreciated.
As mentioned by #cyborg86pl when switching flash modes you should not switch CONTROL_AE_MODE . Instead you can switch between FLASH_MODEĀ“s. Here is a working example for my case:
when (currentFlashState) {
FlashState.AUTO -> {
previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH)
}
FlashState.ON -> {
previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON)
previewRequestBuilder.set(CaptureRequest.FLASH_MODE, CameraMetadata.FLASH_MODE_TORCH)
}
FlashState.OFF -> {
previewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON)
previewRequestBuilder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF)
}
}
previewRequest = previewRequestBuilder.build()
captureSession.setRepeatingRequest(previewRequest, captureCallback, backgroundHandler)
I don't know why your preview turn black, but you don't need to close capture session manually. From .close() method's docs:
Using createCaptureSession(List , CameraCaptureSession.StateCallback,
Handler) directly without closing is the recommended approach for
quickly switching to a new session, since unchanged target outputs can
be reused more efficiently.
So you can reuse existing CaptureRequest.Builder, set your changed value, build new PreviewRequest and just start new session with this new request, like this:
try {
// Change some capture settings
mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
// Build new request (we can't just edit existing one, as it is immutable)
mPreviewRequest = mPreviewRequestBuilder.build();
// Set new repeating request with our changed one
mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
It will be much faster (almost without any visible freeze of preview).
What you want is disabling flash, not auto-exposure (AE), thus you want to use CONTROL_AE_MODE_ON rather than CONTROL_AE_MODE_OFF.
As mentioned in the documentation:
CONTROL_AE_MODE_ON
The camera device's autoexposure routine is active, with no flash control.
I try my best to describe my situation.
My wicket site contains list wicket component, where every list element has another list. Each element in lowest level list has ajax wicket link to download some file. All this works fine. I used to this AjaxBehaviour. Method startDownload of this behaviour is invoked within link onClick method.
public void startDownload(AjaxRequestTarget target) {
target.appendJavaScript("window.location.href='" + getCallbackUrl() +"'");
}
Method onRequest of this behaviour is:
#Override
public void onRequest() {
IRequestHandler fileTarget = new IRequestHandler() {
#Override
public void respond(IRequestCycle requestCycle) {
if (null != file) {
try {
FileInputStream inputStream = new FileInputStream(file);
WebResponse resp = (WebResponse) requestCycle.getResponse();
resp.setAttachmentHeader(fileName);
String contentType = FileUtils.getFileType(fileName);
if (contentType != null) {
resp.setContentType(contentType);
}
resp.setHeader("Pragma", "anytextexeptno-cache");
resp.setHeader("Cache-Control", "max-age=0");
Streams.copy(inputStream, requestCycle.getResponse().getOutputStream());
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
Now i need to reload model and refresh some components in the page after download file action. I tried to add entire page to the AjaxRequestTarget in method onclick, after code invoked startDownload method. Reload page works fine but window with file to download doesn`t show.
I think that i have to do reload page in other, separate request (maybe i'm mistaken? ), because in this request i call 'window.location.href=....', but i don`t know how i can to enforce second request to reload page.
Does have someone some ideas what I do wrong ? And how can I resolve my problem ?
Seems you need something like this:
https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
It seems that my implementation is simmilar to this from cwiki.apache.org website. In onRequest method i used getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler), and despite of this doesn`t work.
Is possible that reason of this is component, which cause request is added to target (because i add to target entire page and component - ajaxLink in this example, is child of this page)
How to enable the default text highlights menu like: Copy/Paste/Search/Share in android webview ?
Working on Android 1.5 - 2.3 you can use emulateShiftHeld() made public since 2.2 but now is deprecated. this method put your WebView into text selection mode.
https://developer.android.com/reference/android/webkit/WebView.html#emulateShiftHeld%28%29
Unfortunately there's no copy/paste/search/share function integrated in Android, since Android 2.0 the text selection
can be driven by touch but other than that, there's no other thing you can do.
I found a workaround for this
Check out method selectText() on WebView (it's not in API, but can be invoked using reflection)
here is my full method source code:
public void startTextSelection() {
try {
WebView.class.getMethod("selectText").invoke(this);
} catch (Exception e) {
try {
WebView.class.getMethod("emulateShiftHeld").invoke(this);
} catch (Exception e1) {
KeyEvent shiftPressEvent = new KeyEvent(0, 0,
KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT, 0, 0);
shiftPressEvent.dispatch(this);
Toast.makeText(getContext(), R.string.select_text, Toast.LENGTH_LONG).show();
}
}
}
Works on ICS too.
Try this:
mWebView.setHapticFeedbackEnabled(true);
mWebView.setLongClickable(true);
I am developing in J2ME, I need to show a text, and then an underlined link / button that people can press.
I cannot use Canvas.
As a temporal solution, I am using the typical command button but I would like to show this option on screen.
(I don't want to use any framework that implies to change everything so that it has a particular look, only an underlined link)
I found it, uff!!!
Command prospectoCommand = new Command("Prospecto", Command.EXIT, 1);
StringItem messageItem2 = new StringItem("", "", Item.HYPERLINK);
messageItem2.setText("push to go to the URL");
ItemCommandListener listener = new ItemCommandListener() {
public void commandAction(Command cmnd, Item item) {
if(cmnd==prospectoCommand)
{
try {
midlet.platformRequest(URL);
} catch (ConnectionNotFoundException ex) {
ex.printStackTrace();
}
}
}
};
messageItem2.setDefaultCommand(prospectoCommand);