How to implement JavaCameraView on top of screen - android

So currently i am having troubles on dealing with my problems. What I want to achieve basically is to open a JavaCameraView while still be able to operate the phone normally.
I have managed to follow the guide here and used this in my styles.xml file
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
What this xml has achieved is that it has successfully managed to make the background transparent, but I can't click anything on the background.
If I want to be able to click background items (operate my phone normally), while keeping the JavaCameraView on top, how can i achieve that?
Here is my onCreate() code if needed.
#Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "onCreate");
super.onCreate(savedInstanceState);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_main);
mOpenCvCameraView = (JavaCameraView) findViewById(R.id.tutorial1_activity_java_surface_view);
mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
mOpenCvCameraView.setCvCameraViewListener(this);
mOpenCvCameraView.setZOrderOnTop(true);
SurfaceHolder CameraViewHolder = mOpenCvCameraView.getHolder();
CameraViewHolder.setFormat(PixelFormat.TRANSPARENT);
}
activity_main.xml
[<!-- language: xml -->]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.os10.testproject.MainActivity">
<org.opencv.android.JavaCameraView
android:id="#+id/tutorial1_activity_java_surface_view"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="top"
android:screenOrientation="portrait"
android:visibility="visible"
opencv:camera_id="front"
opencv:show_fps="true" />
</RelativeLayout>
Many thanks.

So i found out that what i need is a floating window.
I will leave a link here which helps me in solving my problem to help anyone having the same problem as mine.
Cheers.

Related

Android Splash Screen shifts

I have an Android Splash Screen which renders a drawable. When it is opened via a cold start, I find that my asset simply shifts in an upward direction.
You can find the appropriate code below, all unnecessary code has been omitted.
Here's the slight shift:
SplashActivity.java
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, R.style.SplashTheme);
super.onCreate(savedInstanceState);
}
res/drawable/background_splash.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<item android:drawable="#color/splash_background_color"/>
<item
android:gravity="center"
>
<bitmap
android:src="#drawable/x150"/>
</item>
</layer-list>
res/layout/launch_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/splash_background_color">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/background_splash"
/>
</FrameLayout>
res/values/styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
</resources>
I found the solution:
You should remove ImageView because you've already set splash via android:windowBackground.
Also remove android:background="#color/splash_background_color" from FrameLayout to make it transparent
Btw, you could delete res/layout/launch_screen.xml if you are not going to draw some layouts over your splash.
For Activity don't call setContentView()
For Fragment don't override onCreateView()
It's ok, Android doesn't require to set layout for them.
In styles.xml, replace:
<item name="android:windowBackground">#drawable/background_splash</item>
with
<item name="android:background">#drawable/background_splash</item>
Note the windowBackground -> background
That solves the issue for me.

how to delete the toolbar in android design

The red frame should not have in my code, but after I updated my Android Studio, it is showed in all of my APPS. please click and see the picture.
How to delete the red frame from my code? And it could not find in its design/text. The blue frame's begin code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/activity_login_user_email_edt"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:paddingLeft="35dp"
android:autoText="true"
android:hint="e-mail" />
The Answer Skynet posted is correct,but this is the programatical way
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Full Screen and remove toolbar
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
That is the theme your activity is extending from. You change it in the styles.xml. Then you need to update this setting in the Manifest.
You need to add this to styles.xml:
<style name="Theme.AppCompat.Light.NoActionBar.FullScreen" parent="#style/Theme.AppCompat.Light">
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
</style>
Then in your AndroidManifest.xml for this Activity:
<activity
android:name=".YourActivity"
android:label="#string/title_activity_main"
android:screenOrientation="landscape"
android:theme="#style/Theme.AppCompat.Light.NoActionBar.FullScreen">
</activity>
The above will work if you are extending from AppCompatActivity which should look like:
public class YourActivity extends AppCompatActivity{}

Applying Checkbox Styles in Android PreferenceActivity

I am writing an application that SDK 10+. I would like all of my check boxes in my Activities as well as my PreferenceActivity to look the same. I created a Theme that has a Theme.Black parent. I created a child style of android:Widget.CompoundButton.CheckBox and set the android:checkboxStyle to that child theme. I have applied my theme across the entire app in the application manifest element with:
android:theme="#style/AppTheme"
When I look at the main Activity, the check box style has been applied as expected, but the checkbox in the PreferenceActivity does not have the style. My questions are:
Is it possible to style minor parts of preferences without having to specify an entire new layout for each one?
More generally, I would like to do this for other controls that show up in the preferences, like toggles or switches. Is that possible? (My guess is that the solution to one will pretty much be able to be applied to those particular issues as well)
I know there is an issue for nested preferences, but this question is applicable to Preferences at the top level. Any help is greatly appreciated. I have been banging my head against a wall on this one for a couple hours now...
Here is what I have so far:
prefs.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference
android:key="checkbox1"
android:summary="This is a themed checkbox preference"
android:title="Checkbox 1" />
</PreferenceScreen>
ThemedPreferenceActivity.java
public class ThemedPreferencesActivity extends PreferenceActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<CheckBox
android:id="#+id/checkBox1"
android:text="CheckBox"
android:checked="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" style="#style/AppTheme.Preference.Checkbox" />
</LinearLayout>
MainActivity.java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
style.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="AppTheme" parent="android:Theme.Black">
<item name="android:checkboxStyle">#style/AppTheme.Preference.Checkbox</item>
</style>
<style name="AppTheme.Preference.Checkbox" parent="android:Widget.CompoundButton.CheckBox">
<item name="android:button">#drawable/pref_checkbox</item>
<item name="android:background">#FF0000</item>
</style>
</resources>
pref_checkbox.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:drawable="#android:drawable/ic_menu_call" />
<item android:state_checked="false" android:drawable="#android:drawable/ic_menu_camera" />
</selector>
Looks like the issue was with the line:
<style name="AppTheme.Preference.Checkbox" parent="android:Widget.CompoundButton.CheckBox">
<item name="android:button">#drawable/pref_checkbox</item>
<item name="android:background">#FF0000</item> <---- RIGHT HERE
</style>
Looks like specifying that was causing the check box to misbehave. Turns out that I didn't need that anyway (and in fact, realized I would do it in the "ListView" style anyway if I wanted it) so, problem solved.

Android: custom title style

I have a listactivity with iconified text which I'm giving a custom title. Here's my custom_style.xml:
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#222222</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">50dip</item>
<item name="android:windowTitleBackgroundStyle">#style/CustomWindowTitleBackground</item>
</style>
</resources>
Here's the layout for the title, window_title.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:gravity="center_vertical"
android:paddingLeft="10dip"
android:background="#222222">
<ImageView
android:id="#+id/header"
android:src="#drawable/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
I set the new title style in onCreate:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
// if it wasn't a listactivity, here I'd use
// setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
browseToRoot();
}
My problem is that the styled title bar appears at the correct size and with the correct background colour (taken from custom_style.xml) but eveything in window_title.xml is ignored. The rest of the listadapter still works fine. In a very similar question here: Custom title with image it says setFeatureInt must come before super.onCreate but either way my result is the same.
I've tried replacing the imageview with a nice simple textview, but the entire window_title.xml seems to be ignored. Any ideas where I'm going wrong? Many thanks, Baz.

Why is not possible for linear layout to have style attributes

I have defined a style for Linear layout but the layout is not visible in graphical view of main.xml
main.xml.
<LinearLayout style="VerticalThemeLayoutInputs">
styles.xml
<resources>
<style name="VerticalThemeLayoutInputs">
<item name="android:background">#6699FF</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
</style>
</resources>
Edit:
But below code will work fine but I don't want this code
<LinearLayout
android:background="#6699FF"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
Interesting Fact
I used a scrollview. Within that I placed many Linear layout. Layouts properties are almost same so I decided to have a style for that. But what is happening know? the layout is not visible only in graphical-view but it works fine in emulator.
But actually what is happening? I think its due to Scroll view.
I think what you want is style="#style/VerticalThemeLayoutInputs".
E.g.
<LinearLayout
style="#style/VerticalThemeLayoutInputs">
main.xml in res/layout/:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/VerticalThemeLayoutInputs"
>
</LinearLayout>
styles.xml in res/values/:
<?xml version="1.0" encoding="UTF-8"?>
<resources>
<style name="VerticalThemeLayoutInputs">
<item name="android:background">#6699FF</item>
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:orientation">horizontal</item>
<item name="android:gravity">center_vertical</item>
</style>
</resources>
onCreate method in activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
...
<item name="android:layout_marginTop">#dimen/margin_top</item>
remove this tag and check.. this seems to be an invalid one.. and in main.xml add style="#style/VerticalThemeLayoutInputs" just like the above answer given by steve
Are you sure from that the style.xml located in Value folder NOT in Ar/EN/..
because he called the default in the first "value\style.xml "

Categories

Resources